1

I am loading list view by listview adapter class. Within that list view I have button called favorite.

ImageButton mFavorite = (ImageButton) convertView.findViewById(R.id.method_fav_btn);

There are multiple image buttons under the same id. I want to identify which button was pressed by means of setting some extra parameters to it. I am doing this for that:

mFavorite.setId(pm.getId());

And on click:

mFavorite.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        System.out.println("Id is: "+mFavorite.getId());
    }
});

But, the problem is, I have 3 items in list view. Every time I am getting same id. How to get different ids on different clicks? Thanks.

RNK
  • 5,582
  • 11
  • 65
  • 133

1 Answers1

1

You can use the setTag() + getTag() methods.

See here for a similar question and here for the official documentation.

Community
  • 1
  • 1
Sebastiano
  • 12,289
  • 6
  • 47
  • 80