DEV Community

Cover image for How to Disable Button in Android Studio
Anoop Patel
Anoop Patel

Posted on

2

How to Disable Button in Android Studio

*First Way: *

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                view.setEnabled(false);
            }
        });
Enter fullscreen mode Exit fullscreen mode

Second way: Without setOnClickListner

 public void disable(View v){
        v.setEnabled(false);
    }
Enter fullscreen mode Exit fullscreen mode

*XMl code file: *

 <Button
        android:id="@+id/button"
        android:onClick="disable"
        android:layout_margin="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button" />
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay