Reputation: 53
I have created a listview which displays all the people in the database. But how do I get the row id of the one I select so I can pass that infomation to the next activity.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.load_game1);
listContent = (ListView)findViewById(R.id.contentlist);
mDbAdapter = new DbAdapter(this);
mDbAdapter.open();
Cursor cursor = mDbAdapter.fetchAll();
startManagingCursor(cursor);
String[] from = new String[]{DbAdapter.KEY_NAME, DbAdapter.KEY_ROWID};
int[] to = new int[]{R.id.text};
cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
listContent.setAdapter(cursorAdapter);
mDbAdapter.close();
}
Which displays displays http://i.minus.com/iGEtGKGyF1Wgc.png
Now I want to click on a name get that row id from the database.
Upvotes: 0
Views: 3472
Reputation: 27455
You have to register implement and add an OnItemClickListener to the list so you can react when an item was clicked. The item id will be passed into the onListItemClick() method of the OnItemClickListener.
Upvotes: 0
Reputation: 14808
Use setOnItemClickListener
on your Listview
then you will get the id of the selected item (item id start from 0 but Database _id column is start from 1 so you should send id+1
, please confirm this).
And send the id using intents.
Upvotes: 1