Can't Getting Data From Cursor Adapter
I have a ListView (in an Activity and not in a ListActivity) that utilizes a custom cursor adapter to get some data from my local db and show them inside the ListView. lv.setOnItem
Solution 1:
The arg0
parameter in your OnItemClickListener
is the ListView
. However, you can just do
lv.setOnItemClickListener(newOnItemClickListener() {
@OverridepublicvoidonItemClick(AdapterView<?> arg0, View view, int position, long id) {
// This will get the cursor from the adapter, already moved to positionCursorcursor= (Cursor) mCursorAdapter.getItem(position)
//get the data...
}
});
Solution 2:
Inside the getView
method you should use something like this
view.setTag(data); // you can pass here your specific data for each item
Supposing your data is just an integer, then you can get this value from the onItemClick()
in this way:
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
Integerdata= (Integer) view.getTag();
// your operation
}
Post a Comment for "Can't Getting Data From Cursor Adapter"