How to set some extra information for each item on GridView in Android?
-
12-11-2019 - |
Question
I have a GridView in which every item must have an ID other than its position in the grid so that I can pass that id using Intents to another activity?
How can I specify this extra parameter and how can I access it inside onItemClick
method?
Edit:
int catID = cu.getInt(0);
myView.setTag((Object) catID);
That's how I use setTag
method.
Intent categoryActivity = new Intent(getParent(), CategoryActivity.class);
categoryActivity.putExtra("itemId", (Integer) v.getTag());
startChildActivity("CategoryActivity", categoryActivity);
And this how I use getTag
.
I'm wondering if I'm doing it correctly?!
Solution
You can use View.setTag()
and View.getTag()
methods for this.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow