DEV Community

Mohasin-Nawaz091
Mohasin-Nawaz091

Posted on

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:

 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)