user3298896
user3298896

Reputation: 15

How to open a new activity when a button is clicked?

I am making an android app and I want it so that when someone clicks a button in the main menu activity, they are taken to the corresponding activity. At the moment my code is:

  1. button in menu xml:

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Dwight Quotes"
    android:id="@+id/DwightButton"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:onClick="openNewActivity"
    android:background="#EAD383"
    android:enabled="false" />
    
  2. the menu java:

    public void openNewActivity(View view) {
    // Do something in response to button
    Intent intent = new Intent(this, Dwight.class);
    startActivity(intent);
    

when I click the button nothing happens. Can someone explain what I need to do?

Upvotes: 0

Views: 57

Answers (1)

Farouk Touzi
Farouk Touzi

Reputation: 3456

Remove android:enabled="false" from your code.

Upvotes: 5

Related Questions