- setTag() getTag. , .
public View getView(int position, View convertView, ViewGroup parent) Imageview .
ImageView temp = (ImageView) v.findViewById(resId);
temp.setImageResource(icon);
temp.setTag(icon);
Then in onClickyou just compare View vwith your id drawable. For example, I wanted to change the image on click, and I encoded it that way. Pay attention to how I also change the tag when setting a new method
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if ((Integer)v.getTag() == R.drawable.current_img) {
v.setBackgroundResource(R.drawable.new_img);
v.setTag(R.drawable.new_img);
}
}
});
source
share