I have 3 Buttons
.
When i click on any of the Buttons
, i want the color of the Button
to change if the Button
text matches with a String
in a variable String ans;
.
Can someone help me?
Here is what i have tried:
public void onClick(View v) {
// TODO Auto-generated method stub
if((btn10.getId())==(R.id.btn10))
{
if(btn10.getText().toString().equals(ans))
{
btn10.setBackgroundColor(Color.GREEN);
score=score+10;
}
else
{
if((btn11.getId())==(R.id.btn11))
{
btn10.setBackgroundColor(Color.RED);
}
if((btn12.getId())==(R.id.btn12))
{
btn12.setBackgroundColor(Color.RED);
}
ch=ch-1;
}
}
else if((btn11.getId())==(R.id.btn11))
{
if(btn11.getText().toString().equals(ans))
{
btn11.setBackgroundColor(Color.GREEN);
score=score+10;
}
else
{
if((btn12.getId())==(R.id.btn12))
{
btn12.setBackgroundColor(Color.RED);
}
if((btn10.getId())==(R.id.btn10))
{
btn10.setBackgroundColor(Color.RED);
}
ch=ch-1;
}
}
else if((btn12.getId())==(R.id.btn12))
{
if(btn12.getText().toString().equals(ans))
{
btn12.setBackgroundColor(Color.GREEN);
score=score+10;
}
else
{
if((btn11.getId())==(R.id.btn11))
{
btn11.setBackgroundColor(Color.RED);
}
if((btn10.getId())==(R.id.btn10))
{
btn10.setBackgroundColor(Color.RED);
}
ch=ch-1;
}
}
}
Any help is appreciated, thanks in advance.