Reputation: 7191
I would like to know how I can change image in imageview but in specific way. I would like to when I start application I have a default icon and when I click on them I change icon on the othe. But when I click again my icon return to default, and again.... This is what I got at this moment:
final ImageView check_box = (ImageView) rowView.findViewById(R.id.email_list_item_checkbox_icon);
check_box.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
check_box.setImageResource(R.drawable.checkbox_android);
}
});
How I can do next step and loop this solution?
Upvotes: 0
Views: 279
Reputation: 6604
Simple, As per your requirement. Just take a boolean flag variable.
@Override
public void onClick(View arg0) {
if ( !flag) {
check_box.setImageResource(R.drawable.checkbox_android);
flag = true;
}
else {
check_box.setImageResource(R.drawable.other_image);
flag = false;
}
});
Upvotes: 1
Reputation: 11508
ImageView check_box = (ImageView) rowView.findViewById(R.id.email_list_item_checkbox_icon);
check_box.setTag(R.id.email_list_item_checkbox_icon);
check_box.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Integer integer = (Integer) view.getTag();
switch(integer) {
case R.id.email_list_item_checkbox_icon:
check_box.setDrawableResource(R.drawable.checkbox_android);
check_box.setTag(R.drawable.checkbox_android);
break;
case R.drawable.checkbox_android:
check_box.setDrawableResource(R.id.email_list_item_checkbox_icon);
check_box.setTag(R.id.email_list_item_checkbox_icon);
break;
}
}
});
Upvotes: 1
Reputation: 10877
You can use some flags which becomes true to default icon and false to checked icon. Using flag you can achieve your part of goal.
Upvotes: 1