Issue
I need to see if there is a way where I can test for what background a button has. For example, here is my pseudo code:
if (button background is `R.drawable.black`) {
button.setBackground(to R.drawable.white)
}
Is there a way that this if statement can be done? I know how to SET backgrounds, just curious on the test portion.
Solution
In your case, I believe that tags would be useful. Try this:
//When you set the button:
btn.setBackgroundResource(R.drawable.black);
btn.setTag(R.drawable.black);
//When you re-set the button:
if(btn.getTag().equals(R.drawable.black)) {
btn.setBackgroundResource(R.drawable.white);
btn.setTag(R.drawable.white);
}
Answered By - iTurki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.