In my app I have a listview, which when you click on an item i want a dialogfragment to appear with details in it. The listview is populated using a custom cursoradapter and each row is a view extended from a relativelayout.
My thought process is that i would have some kind of id value in the custom view and when selected, the id is used in a new db query to populate the dialogfragment. However, I don't want the id on view in the row, I want it hidden.
I'm thinking that i create a custom view class, extended from relativelayout, and in the view is a field that will hold the id as well as the two textviews.
My main problem is working out how to use my custom view inside the adapter. Every example i have found, inflates an xml layout inside newview, but my xml layout will not include the id field.
Can I just create a new object for my view, inside newview rather than inflating an xml?
Or am I missing something obvious?
Thanks
When you are working with
CursorAdapter
inonItemClick(AdapterView<?> parent, View view, int position, long id)
implementation ofAdapterView.OnItemClickListener
you can get:_id
column from the underlying Cursor - simply, it is thelong id
parameter of this functionany column visible or not in your item view but existing in the Cursor by casting the item at position to the Cursor like:
Cursor c = (Cursor)parent.getItemAtPosition(position);
Now
c
is pointing to the selected row so you are can get any column from it as simple asvar value = c.getInt/String/etc(c.getColumnIndex("columnname"));
Seems like you might be able to use a tag and that would be simpler.