I am developing an application that contains a favorite feature. When the user clicks an image button, it should change its background resource and does something depending on its current background resource. The problem is that I need the button to be continually clickable so that if the user accidentally added an item to favorites, he/she would be able to remove it from favorites.
Here's the onClickListener that does the changes, but it does it only one time inside my activity. Once the user changes the favorite status, he/she can't change it again unless he/she leaves the activity and resumes it again.
ImageButton fav = (ImageButton) findViewById(R.id.fav);
fav.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (item.getIsFav() == 1) {
fav.setImageResource(R.drawable.fav_dimed);
editFavorite("remove from favorites");
} else if (item.getIsFav() == 0) {
fav.setImageResource(R.drawable.fav);
editFavorite("add to favorites");
}
}
});
Any one to help please :)