Reputation: 303
Please help how can we do a Background Resource Check?
Example:
Button button1;
protected void onCreate(Bundle savedInstanceState) {
..........................................
button1 = (Button) findViewById(R.id.example1);
}
public void onclick1 (View v){
button1.setBackgroundResource(R.drawable.example2);
}
public void onclick2 (View v){
My Question Here, checking if button1 button drawable = example2
if (..........................){
//Action
}
If not, when clicked will done another action
else {
//Another Action
}
}
Upvotes: 3
Views: 5695
Reputation: 72563
You can use the getBackground()
method of the View class for both buttons and compare it like this:
if (button1.getBackground().getConstantState().equals(button2.getBackground().getConstantState())) {
}
else {
}
Upvotes: 5