Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.android.helloandroid.MainActivity">
<RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.helloandroid.MainActivity">
<RelativeLayout
@VaidotasK
VaidotasK / OnSave; OnCreate; OnRestore
Created March 25, 2018 22:16
Sample of Java code - OnSaveInstanceState/OnCreate/OnRestoreInstanceState
//Saves data before changing activity
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString(PLAYER_1_NAME, playerAName);
savedInstanceState.putString(PLAYER_2_NAME, playerBName);
savedInstanceState.putInt(SCORE_A, scorePlayerA);
savedInstanceState.putInt(SCORE_B, scorePlayerB);
super.onSaveInstanceState(savedInstanceState);
}
@VaidotasK
VaidotasK / PlaceAdapter.java
Created July 14, 2018 12:43
From PlaceAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_place, parent, false);
}
// Get the {@link Place} object located at this position in the list
Place currentPlace = getItem(position);
@VaidotasK
VaidotasK / PubsFragment.java
Created July 14, 2018 12:46
Pub Fragment in which View.GONE should work
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.place_list, container, false);
final ArrayList<Place> places = new ArrayList<Place>();
places.add(new Place(getString(R.string.church_name_1), getString(R.string.church_address_1), "a",
getString(R.string.church_address_1)));
@VaidotasK
VaidotasK / Place.java
Created July 14, 2018 12:48
Custom class Place
// For pub Fragment
public Place(String name, String address, String price, String description) {
this.name = name;
this.address = address;
this.price = price;
this.description = description;
}
public Place(String name, int placeImageResourceId, String address, String price, String description) {
this.name = name;
@VaidotasK
VaidotasK / Error
Created July 29, 2018 15:25
Error log, app shows only empty state window.
07-29 18:18:41.969 4309-4309/com.example.android.environmentalnews E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener
07-29 18:18:41.979 4309-4309/com.example.android.environmentalnews E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.dispatchApplyWindowInsets
07-29 18:18:41.989 4309-4309/com.example.android.environmentalnews E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.onApplyWindowInsets
07-29 18:18:41.999 4309-4309/com.example.android.environmentalnews E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method android.support.v4.view.ViewCompat.removeOnUnhandledKeyEventListener
07-29 18:18:42.009 4309-4309/com.example.android.environmentalnews E/dalvikvm: Could not find class '