N
N
newdancer2016-08-25 12:36:26
Android
newdancer, 2016-08-25 12:36:26

How to implement click handling on imageview inside item Listview?

How to implement click handling on imageview inside item Listview?
I made my adapter. getView looks like this:

@Override
  public View getView(int i, View v, ViewGroup viewGroup)
  {
    View rootView = v;
    if (rootView == null) {
      rootView = layoutInflater.inflate(R.layout.item_cat, viewGroup, false);
    }

    CatSounds s = getSounds(i);
    ((TextView) rootView.findViewById(R.id.textNameCat)).setText(s.nameCat);
    imageCatPlay = (ImageView) rootView.findViewById(R.id.imageCatPlay);
    imageCatPlay.setTag(i);
    imageCatPlay.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view)
      {
        Log.d("myLogs", "нажата в позиции = " + view.getTag());
        ((ImageView) view.getTag()).setImageResource(R.drawable.pause);
      }
    });
    return rootView;
  }

the application terminates with an error:
java.lang.ClassCastException: java.lang.Integer cannot be cast to android.widget.ImageView

in line
((ImageView) view.getTag()).setImageResource(R.drawable.pause);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2016-08-25
@GavriKos

Well, you put an int in the tag, and cast it to ImageView. You need to get the view by position, and from it already ImageView. For example so. Well, or, most likely, you already have a view in onClick - is it not the one that needs to be changed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question