problem with using button.setPressed(false); in android java code
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 ?
button.setChecked(false);
this is the line that un-checks the radio button !!!
thanks to everyone who tried to help. :)
- ahsan
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.
精彩评论