Results 1 to 1 of 1
- 11-16-2012, 10:23 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
How to get info from ListFragment item
Hi - 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:
Java Code:String item = getListAdapter().getItem(position);
Java Code:String item = getListAdapter().getItem(position).toString();
where position is an integer passed to the onClickItemListener method like so:Java Code:String item = (String) ((Fragment) getListAdapter().getItem(position)).getString(0);
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:Java Code:public void onListItemClick(ListView l, View v, int position, long id)
Any suggestions would be most welcome, thanks!Java 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<Cursor>) this); } @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { String selection = "stitchlevel=?"; String[] selectionArgs = new String[] {args.getString("Level")}; return (Loader<Cursor>) new CursorLoader(getActivity(), STITCHES_URI, PROJECTION, selection, selectionArgs, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { mAdapter.swapCursor((android.database.Cursor) cursor); }
Similar Threads
-
remove *this item/object from arrayList and window(jframe) via item button
By droidtech1 in forum New To JavaReplies: 10Last Post: 09-04-2012, 08:12 AM -
How to add item on list
By Aenohe in forum New To JavaReplies: 4Last Post: 12-08-2011, 11:05 PM -
Item Flickering
By vincy in forum CLDC and MIDPReplies: 0Last Post: 10-25-2011, 07:48 AM -
getting first item in a linkedList
By TopNFalvors in forum New To JavaReplies: 4Last Post: 04-01-2011, 03:26 PM -
Getting an item from an array
By ile4 in forum New To JavaReplies: 9Last Post: 01-13-2011, 03:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks