android: Identify individual items in row of ListView? -


i have listview in listactivity populated database table. each row of listview relativelayout 3 textviews named rowid, date, , name in order. able select individual rows programmatically using .setselection(int position) method of listview.

here i'm trying do: when push button on interface, rowid selected list row, , perform db query using rowid. can't figure out how rowid list itself. rowid may not same id or position on list rowid in database.

i suspect require working adapter, i've been trying/searching web week , haven't been able figure out. can provide.

you know list position of selected item, have button outside listview should trigger action on item, , you're not making listview rows (or child view within each row) clickable. right?

you can information list's adapter. getitem(int position) returns object represented list item @ position, can retrieve information need directly if it's stored in object. getview(int position) returns view row, allowing use findviewbyid(int id) retrieve textview.

if don't have adapter, can listview using getadapter().

// listview mylistview = listview in question // int selectedrow = selected row in listview // each row in listview backed object of type mycustomdataclass  int dbrowid; adapter adapter = mylistview.getadapter();  mycustomdataclass data = (mycustomdataclass) adapter.getitem(selectedrow); dbrowid = data.getdatabaserowid(); // or dbrowid = data.rowid; // or whatever method object has getting id.  // or view listviewrow = adapter.getview(selectedrow); textview dbrowview = (textview) listviewrow.findviewbyid(r.id.rowid); string dbrowasstring = dbrowview.gettext().tostring(); dbrowid = integer.parseint(dbrowasstring); 

you might consider whether more natural user tap listview row, rather selecting row , pressing button. reno's answer might work better.


Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -