how to match a string with the button text in android?
<p>I have 3 <code>Buttons</code>.</p>

<p>When i click on any of the <code>Buttons</code>, i want the color of the <code>Button</code> to change if the <code>Button</code> text matches with a <code>String</code> in a variable <code>String ans;</code>.</p>

<p>Can someone help me?</p>

<p>Here is what i have tried:</p>

<pre><code>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;
            }
        }
    }
</code></pre>

<p>Any help is appreciated, thanks in advance.</p>
