Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

java - Android Multiple Intents - One Form

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@Meryl2 When u are using ""android:onClick="btnLogout"""

Then you should have corresponding method public void btnLogout(View view{ //your code here }

Same applies for all buttons in your code


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...