Note that there are some explanatory texts on larger screens.

plurals
  1. POListview Adapter and Listener in Android?
    primarykey
    data
    text
    <p>I am having trouble with my listview adapter and Listener. I am kind of new to Android and I think I set it up correctly. I want my onclicklistner to just display the name of the selected list item. Eventually I want it to do more. Whenever I try to run this tab I get a force close. It leads me to believe there is an issue before the onclicklistner. am I constructing a SherlockList Fragment incorrectly? </p> <pre><code>public class HerbsFragment extends SherlockListFragment implements ActionBar.TabListener{ private View herbView; /** An array of items to display in ArrayList */ String organs[] = new String[]{ "Liver", "Kidneys", "Eyes", "Heart", "Blood" }; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ //super.onCreateView(inflater, container, savedInstanceState); herbView = inflater.inflate(R.layout.main, container, false); ListView listView = (ListView)(herbView.findViewById(R.id.listview)); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, organs); listView.setAdapter(adapter); OnItemClickListener onItemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView &lt;? &gt; arg0, View arg1, int position, long id) { // TODO Auto-generated method stub Toast.makeText(getSherlockActivity(), "You selected :", Toast.LENGTH_SHORT).show(); } }; listView.setOnItemClickListener(onItemClickListener); return herbView;//inflater.inflate(R.layout.main, container, false); } @Override public void onStart() { super.onStart(); /** Setting the multiselect choice mode for the listview */ getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } </code></pre> <p>I posted the logcat </p> <pre><code>06-29 23:49:56.911: E/AndroidRuntime(13875): FATAL EXCEPTION: main 06-29 23:49:56.911: E/AndroidRuntime(13875): java.lang.NullPointerException 06-29 23:49:56.911: E/AndroidRuntime(13875): at in.wptrafficanalyzer.actionbarsherlocknavtab.HerbsFragment.onCreateView(HerbsFragment.java:43) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.os.Handler.handleCallback(Handler.java:587) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.os.Handler.dispatchMessage(Handler.java:92) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.os.Looper.loop(Looper.java:130) 06-29 23:49:56.911: E/AndroidRuntime(13875): at android.app.ActivityThread.main(ActivityThread.java:3691) 06-29 23:49:56.911: E/AndroidRuntime(13875): at java.lang.reflect.Method.invokeNative(Native Method) 06-29 23:49:56.911: E/AndroidRuntime(13875): at java.lang.reflect.Method.invoke(Method.java:507) 06-29 23:49:56.911: E/AndroidRuntime(13875): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 06-29 23:49:56.911: E/AndroidRuntime(13875): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 06-29 23:49:56.911: E/AndroidRuntime(13875): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>My listview is defined in my main.xml </p> <pre><code>&lt;ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; </code></pre>
    singulars
    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