Android: Dynamically change Image in Listview

前端 未结 5 2131
傲寒
傲寒 2021-02-04 07:08

I have a listview defined by the following xml. I need to toggle the image in the list during runtime when the user clicks on any row. How can I achieve this? A

5条回答
  •  忘掉有多难
    2021-02-04 07:59

    Use

    public void setImageResource (int resId);
    

    method of ImageView class.

    P.S. My previous answer seems incomplete, here is the whole solution:

    ImageView imageView = (ImageView) this.findViewById(R.id.img);
                    ((BitmapDrawable)imageView.getDrawable()).getBitmap().recycle();
                    imageView.setImageResource(R.drawable.new_image);
                    imageView.invalidate();
    

提交回复
热议问题