How to disable an Android button?


Question

I have created a layout that contains two buttons, Next and Previous. In between the buttons I'm generating some dynamic views. So when I first launch the application I want to disable the "Previous" button since there wont be any previous views. I also want to disable the "Next" button when there are not more views to display. Is there anyway to disable the buttons?

screen shot of sample layout

1
340
10/22/2011 4:41:36 AM

Accepted Answer

Did you try this?

myButton.setEnabled(false); 

Update: Thanks to Gwen. Almost forgot that android:clickable can be set in your XML layout to determine whether a button can be clickable or not.

745
9/1/2014 7:00:54 PM

You can't enable it or disable it in your XML (since your layout is set at runtime), but you can set if it's clickable at the launch of the activity with android:clickable.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon