Reputation: 2126
As I read from android sample, if I use SimpleCursorAdapter, it automatically set the id of list view to primary key of the table, so if I call the following event :
protected void onListItemClick(ListView l, View v, int position, long id)
{
......
}
I can easily determine which item (row) of database has been selected, by reading the id parameter.
But I am populating my list view by implementing my own custom ArrayAdapter. As I explained in my former question. So I don't know how to get the selected ID of list view item.
My table just has two column, the _Id of long type and is primary key, and name of nvarchar type.
Thanks.
Upvotes: 0
Views: 115
Reputation: 493
As your List<T>
consists of custom data container objects, you just have to add a method such as getPrimaryKey()
to that data container class. Now, in the method onListItemClicked
, you can easily read that key by doing
DataContainer dataContainer = myDataList.get(position);
int primaryKey = dataContainer.getPrimaryKey();
or simply
int primaryKey = myDataList.get(position).getPrimaryKey();
Upvotes: 1
Reputation: 1661
Extend CursorAdapter instead of ArrayAdapter. Then override bindView and newView to implement custom logic and behaviour.
Upvotes: 0