Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - getListView() error in ListFragment
    primarykey
    data
    text
    <p>I am using a ListFragment in my app and I want to make it so that there is a OnItemClick Listener for each item in the list but when I add <code>ListView lv = getListView();</code> I get an error. If I remove that the listview works But then there will be no onclick listener which I need for my App.</p> <p>Below is my code</p> <pre><code>@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); //... ListAdapter adapter = new SimpleAdapter(getActivity(), menuItems, R.layout.list_item, new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] { R.id.name, R.id.desciption, R.id.cost }); setListAdapter(adapter); ListView lv = getListView(); //HERE IS WHERE I AM GETTING THE ERROR lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // getting values from selected ListItem String name = ((TextView) view.findViewById(R.id.name)).getText().toString(); String cost = ((TextView) view.findViewById(R.id.cost)).getText().toString(); String description = ((TextView) view.findViewById(R.id.desciption)).getText().toString(); // Starting new intent Intent in = new Intent(getActivity().getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(KEY_NAME, name); in.putExtra(KEY_COST, cost); in.putExtra(KEY_DESC, description); startActivity(in); } }); return super.onCreateView(inflater, container, savedInstanceState); } </code></pre> <p>Logcat is below</p> <pre><code>08-01 23:24:47.152: E/AndroidRuntime(18883): FATAL EXCEPTION: main 08-01 23:24:47.152: E/AndroidRuntime(18883): java.lang.IllegalStateException: Content view not yet created 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.ListFragment.getListView(ListFragment.java:222) 08-01 23:24:47.152: E/AndroidRuntime(18883): at com.OptimusApps.stayhealthy.AndroidXMLParsingActivity.onCreateView(AndroidXMLParsingActivity.java:74) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1470) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:925) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1102) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1458) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:438) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.os.Handler.handleCallback(Handler.java:605) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.os.Handler.dispatchMessage(Handler.java:92) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.os.Looper.loop(Looper.java:137) 08-01 23:24:47.152: E/AndroidRuntime(18883): at android.app.ActivityThread.main(ActivityThread.java:4575) 08-01 23:24:47.152: E/AndroidRuntime(18883): at java.lang.reflect.Method.invokeNative(Native Method) 08-01 23:24:47.152: E/AndroidRuntime(18883): at java.lang.reflect.Method.invoke(Method.java:511) 08-01 23:24:47.152: E/AndroidRuntime(18883): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 08-01 23:24:47.152: E/AndroidRuntime(18883): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 08-01 23:24:47.152: E/AndroidRuntime(18883): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload