views:

56

answers:

2

Hi Everyone,

I want to disable the button press on a 2nd click, so I have this code for the action handler of the button in my android code :

      // do something when the button is clicked

       public void onClick(View v) {

        final Button button = (Button)findViewById(R.id.radio_red);

        if(button.isPressed()==true && rt1==true ) 

        {

            button.setPressed(false);

            button.clearFocus();

            //rt1=false;

                    //do some processing !     

        }

        else rt1=true;

    }'

However, button.setPressed(false); doesnt work as expected. :(

Can anyone please help me out ?

A: 

I think you want to replace the entire code with button.setClickable(false) - that way, your onClick() handler will be called the first time it is clicked, but any subsequent click won't do anything.

Personally, I think it's better UI design if you call button.setEnabled(false) - that makes it obvious to the user that the button cannot be pressed.

EboMike
What I want to do is this : When you click/press on the button once, its selected/pressed, you click/press another time and it gets deselected/unpressed ! Am I doing anything wrong here ?
Ahsan
So you want a toggle button?
EboMike
well, it works like toggle button, but the outlook is of a radio button ! (you can choose and un-choose the selection!!!) I want the GUI to look like a radio button !
Ahsan
I'm confused. Why are you not using RadioButton then?
EboMike
because, even then its not working, the button is not getting un-pressed :(
Ahsan
i guess it works now....donno why it was not working earlier..thanks :)... btw, is there a way to change the radio button image ?
Ahsan
Look here, under Custom Button: http://developer.android.com/resources/tutorials/views/hello-formstuff.html
EboMike
thanks.........
Ahsan
A: 

button.setChecked(false);

this is the line that un-checks the radio button !!!

thanks to everyone who tried to help. :)

- ahsan

Ahsan