Multiple Intents On Main Menu
Good afternoon, I am a new user to Android eclipse.I have created a Menu with 3 buttons which will lead the user onto 3 seperate pages given their choice, each given their own inte
Solution 1:
You should use a handler method for the onClick event:
<Button...android:onClick="handleClick()
..."/>
in code:
publicclassMainMenuextendsActivity {
...
publicvoidhandleClick(View view){
//do stuff
}
}
edit:
more concrete answer, given your code:
...
<Button
android:id="@+id/btnWorkout"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_alignLeft="@+id/btnhealth"
android:layout_below="@+id/imageView1"
android:layout_marginTop="36dp"
android:text="Log/View Workout"
android:onClick="btnWorkout"/>
<Button
android:id="@+id/btnhealth"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Health Tips"
android:onClick="btnhealth"/>
<Button
android:id="@+id/btnLogout"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_alignLeft="@+id/btnhealth"
android:layout_below="@+id/btnhealth"
android:layout_marginTop="22dp"
android:text="Logout"
android:onClick="btnLogout"/>
...
the attribute value of the android:onClick attribute is the name of the method that it will look for, in the corresponding java code for the activity...(keep in mind the signature of the method must the correct signature for a button click event handler, look at android docs for that ..)
I suggest you pick a different method name so that you don't get the id and the method name confused, as they are two separate references
Post a Comment for "Multiple Intents On Main Menu"