Good afternoon,
I am trying to create a basic menu in my andorid application which contains 5 buttons each bringing you to another form. I am trying to create the java to carry out this action but appear to be running into the following error with each of my buttons
"EXAMPLE cannot be resolved as a variable"
Please help me in a solution to my code or if there is a simpler way to allow me to execute this menu with 5 buttons each going to a different form
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.techblogon.loginexample.MainMenu" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/pic" />
<Button
android:id="@+id/btnFootball"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Football"
android:onClick="btnFootball" />
<Button
android:id="@+id/btnHockey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnFootball"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Hockey"
android:onClick="btnHockey" />
<Button
android:id="@+id/btnLacrosse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnLacrosse"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Lacrosse"
android:onClick="btnLacrosse" />
<Button
android:id="@+id/btnCurling"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnLacrosse"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Curling"
android:onClick="btnCurling" />
<Button
android:id="@+id/btnLogout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnCurling"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Logout"
android:onClick="btnLogout" />
</RelativeLayout>
Here is the Java:
package com.techblogon.loginexample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
public class MainMenu extends Activity {
public void ButtonOnClick(View v) {
switch (v.getId()) {
case R.id.btnFootball:
startActivity(Football);
break;
case R.id.btnHockey:
startActivity(Hockey);
break;
case R.id.btnLacrosse:
startActivity(Lacrosse);
break;
case R.id.btnCurling:
startActivity(Curling);
break;
case R.id.btnLogout:
startActivity(HomeActivity);
break;
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…