Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get info from ListFragment
    primarykey
    data
    text
    <p>I have a ListFragment that is populated using a CursorLoader. Once the ListFragment is populated, I have an OnItemClickListener method in which I want to identify which item from the List Fragment the user chose. How do I do this? I've tried:</p> <pre><code>String item = getListAdapter().getItem(position); String item = getListAdapter().getItem(position).toString(); </code></pre> <p>and</p> <pre><code>String item = (String) ((Fragment) getListAdapter().getItem(position)).getString(0); </code></pre> <p>where position is an integer passed to the onClickItemListener method like so:</p> <pre><code>public void onListItemClick(ListView l, View v, int position, long id) </code></pre> <p>All of these throw Cast Exceptions of one type or another. I'm stumped. This seems like a simple thing to do. For your reference, here's how the List Fragment is populated:</p> <pre><code>private SimpleCursorAdapter mAdapter; private static final String[] PROJECTION = new String[] { "_id", "stitchname" }; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Intent myData = getActivity().getIntent(); Bundle info = myData.getExtras(); String[] dataColumns = { "stitchname" }; int[] viewIDs = { R.id.stitchlist1 }; mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.stitchlist, null, dataColumns, viewIDs, 0); setListAdapter(mAdapter); getLoaderManager().initLoader(0, info, (LoaderCallbacks&lt;Cursor&gt;) this); } @Override public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) { String selection = "stitchlevel=?"; String[] selectionArgs = new String[] {args.getString("Level")}; return (Loader&lt;Cursor&gt;) new CursorLoader(getActivity(), STITCHES_URI, PROJECTION, selection, selectionArgs, null); } </code></pre> <p>Any suggestions would be most welcome, thanks! </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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