Reputation: 1657
I have been experiencing a problem with my custom adapter and have located the problem solution. However I do not know how to go about it. I have researched and seen a few examples of a listview custom adapter at which buttons are given tags like viewHolder.button.setTag(Tag)
and I understand what the tag does but I am unsure as to how to use it. My questions are: When I set the tag on a button, how does the application differentiate my buttons from another if all the tags are set the same? Also, say I have an onClick method in my custom adapter, how do I use the tag that I set to the button to identify the button that was clicked? I've kind of seen similar adapters on the internet but not exactly , a link to an example would be greatly appreciated also.
Upvotes: 0
Views: 336
Reputation: 18977
I am unsure as to how to use it
tag
is a mechanism to make your views
remember something, that could be an object
an integer
a string
or anything you like.
My questions are: When I set the tag on a button, how does the application differentiate my buttons from another if all the tags are set the same?
i do not understand this question but i think if you notice that your button
has a memory and it calls tag
you can use it in a better way. if all of your buttons
memory(tags) are the same so you can not use tags
to distinguish the buttons
you must use ids
.
say I have an onClick method in my custom adapter, how do I use the tag that I set to the button to identify the button that was clicked?
you must set different tags
for your buttons
or grouped them logically and set different tags
for each group then in your onClick
method use the tags
to identify your buttons
group:
OnClickListener myButtonListener = new OnClickListener() {
@Override
public void onClick(View arg0) {
Object obj = arg0.getTag();
if(obj instanceOf groupOneTagObject){
// do action for group 1
}else if(obj instanceOf groupTwoTagObject){
// do action for group 2
}
}
});
Upvotes: 1