-
-
Save jonikarppinen/51e6baeaa5af8d2d74a3bacefa85386b to your computer and use it in GitHub Desktop.
| // Fixes to compilation errors in "Define the onItemClick() method" section | |
| // Doesn't compile | |
| Cursor cursor = parent.getAdapter().getCursor(); | |
| // Fixed (not sure if this is the cleanest way though) | |
| Cursor cursor = ((SimpleCursorAdapter) parent.getAdapter()).getCursor(); | |
| // Doesn't compile | |
| mContactId = getLong(CONTACT_ID_INDEX); | |
| // Fixed | |
| mContactId = cursor.getLong(CONTACT_ID_INDEX); | |
| // Doesn't compile | |
| mContactKey = getString(CONTACT_KEY_INDEX); | |
| // Fixed. Note that the constant defined earlier in the tutorial is LOOKUP_KEY_INDEX | |
| mContactKey = cursor.getString(LOOKUP_KEY_INDEX); |
In addition, the onItemClick event is not triggering. In the contacts_list_item.xml you have to set following properties for the TextView:
android:clickable="false"
android:focusable="false"
Also in contacts_list_view.xml:
`android:id="@android:id/list"`
Should be:
`android:id="@+id/list"`
As the fragment does not recognize this (in @mostafahadian's remark):
`mContactsList = (ListView) getActivity().findViewById(R.id.list);`
Hi there,
I'm getting an error trying to get the ListView object.
contactsList = (ListView) getActivity().findViewById(R.id.list); ... contactsList.setAdapter(cursorAdapter);
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
Do I need to use setContentView() method ?
Hi there,
I'm getting an error trying to get the ListView object.
contactsList = (ListView) getActivity().findViewById(R.id.list); ... contactsList.setAdapter(cursorAdapter);java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
Do I need to use
setContentView()method ?
Try SO answer
That really helped me. Thanks, man!