-4

I am new in android programming and I made a quiz app to learn. In my app there are two buttons and I want to disable one button when user clicks on the other one. Thanks in advance.

This is the two buttons:

This my layout:

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="15.2M"
        android:layout_marginTop="100dp"
        android:layout_marginRight="55dp"
        android:layout_marginLeft="55dp"
        android:id="@+id/submitWrong"
        android:onClick="submitWrong"
        android:background="#faa20a"
        />
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="13.3M"
        android:layout_toRightOf="@id/submitWrong"
        android:layout_marginTop="100dp"
        android:background="#faa20a"
        android:id="@+id/submitCorrect"
        android:onClick="submitCorrect"
        />
Blo
  • 11,903
  • 5
  • 45
  • 99

1 Answers1

1

Try something like this:

public void submitWrong(View v) {
    // does something very interesting
    Button correctBtn = (Button) findViewById(R.id.submitCorrect);
    correctBtn.setEnabled(false);
}

public void submitCorrect(View v) {
    // does something very interesting
    Button wrongBtn = (Button) findViewById(R.id.submitCorrect);
    wrongBtn.setEnabled(false);
}

Also see the button docs

Isaac
  • 1,442
  • 17
  • 26