Reputation: 10840
I am not sure it Android has this, or if there is a method to do so. I looked at the Doc, but haven't seen anything specifically for this use. Is there a preferred method that could be useful? Any help much appreciated.
I need it for an Agenda List with TextView Members. But when a user clicks on one, I need a way to access that agendas info, so like storing an ID from the database to reference that events info, but I need it hidden from the user.
Upvotes: 1
Views: 574
Reputation: 86958
Use setTag()
and getTag()
, you can pass it whatever type of Object you like.
Here's the reference.
Added from comment
I believe it is simplest to query the database a few times rather than have one Cursor holding everything.
For example, if we have a table with columns like: events(_id, name, startTime, endTime, people, etc)
. You could call SELECT * FROM events
but that seems excessive if you only want the details on an event or two. It makes more sense to query SELECT _id, name FROM events
and store this in a ListView. Then you can have:
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
detailCursor = database.rawQuery(`SELECT * FROM events WHERE _id = ?`, new String[] { id });
// Display this event's details somehow
}
}
A secondary cursor, like this, is simplest. You don't allocate memory for used event details and there isn't a significant performance loss from these repeated minor queries. In a case like this I wouldn't store anything in a View's tag, the general cursor (with every event's id and name) and the detail cursor should give you everything you need.
Hope that helps.
Upvotes: 4