How to attach some "metadata" to Android Listview items?
class Venue {
private int id;
private String name;
}
I populate the ListView with something like
List<String> venueNames = data.getVenueNames();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, venueNames));
So after the user selects a particular list item, I'd like to do a SQLite query with the venue id, but this information is lost when creating the venue names. How do you guys s开发者_如何学编程olve this?
EDIT: I should mention that it isn't guaranteed that venue name is unique.
Your problem is here:
List<String> venueNames = data.getVenueNames();
Don't do that. You are the one "losing" the information. If you don't want to lose it, don't lose it.
The simplest thing is to create an ArrayAdapter<Venue>
, and have Venue
's toString()
return name
. Then, calling getItem()
on your ArrayAdapter<Venue>
will return a Venue
.
精彩评论