Issue
ImageButton's background is not getting changed Everything is working counter is getting changed it was working till it was onTouchListener, I changed to onclickListener then changing of background stopped, how should I change background in onClickListener
I tried https://stackoverflow.com/a/11835365/6648201 but it's not helping me
final ImageButton user_btn_like = (ImageButton) view.findViewById(R.id.user_btn_like);
user_btn_like.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(presslikecount ==0) {
user_btn_like.setPressed(true);
presslikecount++;
pressdislikecount = 0;
user_btn_like.setBackgroundResource(R.drawable.ic_user_like_red);
user_btn_dislike.setPressed(false);
user_btn_dislike.setBackgroundResource(R.drawable.ic_user_dislike_black);
like.setText(String.valueOf(presslikecount));
dislike.setText(String.valueOf(pressdislikecount));
}
else
presslikecount--;
user_btn_like.setPressed(false);
user_btn_like.setBackgroundResource(R.drawable.ic_user_like_black);
like.setText(String.valueOf(presslikecount));
}
});
Solution
Use
user_btn_like.setImageResource(R.drawable.ic_user_like_red);
Instead of
user_btn_like.setBackgroundResource(R.drawable.ic_user_like_red);
Answered By - Nitesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.