0

大家好,我正在开发一个应用程序,我在主菜单上设计了一个帮助按钮。我在 drawable 文件夹中复制了一个自定义帮助图像文件,并创建了一个 Help.xml 文件以将其嵌入到布局中。我的功能要求只需单击主菜单上的此帮助按钮,就会弹出包含帮助图像的 help.xml。但是当我单击帮助时没有任何反应。


主菜单.java

Button.OnClickListener mClickListener = new View.OnClickListener() {

        Animation anim = null;

        @Override
        public void onClick(View v) {
            Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            vibe.vibrate(60);

            switch (v.getId()) {
            case R.id.BtnDisplay:
                mpool.play(mlogon, 1, 1, 0, 0, 1);
                anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                anim.setDuration(100);
                mBtn1.startAnimation(anim);
                Intent intent = new Intent(NUGA_MainMenuActivity.this, FileSiganlDisplay.class);
                startActivity(intent);
                //overridePendingTransition(R.anim.zoom_enter,R.anim.zoom_exit);
                overridePendingTransition(R.anim.fade, R.anim.hold);
                break;

            case R.id.BtnSlave:

                mpool.play(mlogon, 1, 1, 0, 0, 1);
                anim = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                anim.setDuration(100);
                mBtn2.startAnimation(anim);
                Intent intent1 = new Intent(NUGA_MainMenuActivity.this, BTSmartSlavemodule.class);
                startActivity(intent1);
                //overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
                overridePendingTransition(R.anim.fade, R.anim.hold);

                break ;
            case R.id.takeashot:
                //snapFunction();
                Intent intent2=new Intent(NUGA_MainMenuActivity.this,ImagesActivity.class);
                startActivity(intent2);
                break;

            case R.id.takehelp :
                Intent intent3=new Intent(NUGA_MainMenuActivity.this,HelpActivity.class);
                startActivity(intent3);
                break;

            default:
                break;
            }

        }
    };

-------------------------------------------------------------------------------------------------

主菜单.xml

</LinearLayout>

    <Button
        android:id="@+id/BtnSlave"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/mes_mod_linked"
        android:background="@color/btn_red"
        android:textColor="#315683"
        android:textSize="30px" />

    <Button
        android:id="@+id/takeashot"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/History"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
         android:background="@color/btn_purple"
        android:textColor="#315683"
        android:textSize="30px" />

    <Button
        android:id="@+id/takehelp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/Help"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
         android:background="@color/btn_yellow"
        android:textColor="#315683"
        android:textSize="30px" />

</LinearLayout>

帮助.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/mainbackground"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/helppicture" />

</LinearLayout>

帮助活动

public class HelpActivity extends Activity{

    Button button1 ; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help);

    }



}

我不确定我错过了什么......请帮忙

4

2 回答 2

1

这样做

public class Mainmenu extends Activity{

    Button button1 ; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help);


       Button BtnSlave = (Button)findViewById(R.id.BtnSlave);
       Button takeashot=(Button)findViewById(R.id.takeashot);
       Button takehelp=(Button)findViewById(R.id.takehelp);

       BtnSlave.setOnClickListener(mClickListener);
       takeashot.setOnClickListener(mClickListener);
       takehelp.setOnClickListener(mClickListener);
    }



}
于 2013-09-10T04:33:27.907 回答
0

在您onCreate()必须为 ClickListener 注册您的按钮,如下所示:

    button1=(Button)findViewById(R.id.BtnSlave); 
      button2=(Button)findViewById(R.id.takehelp);  
      button3=(Button)findViewById(R.id.takeashot);  
        button1.setOnClickListener(mClickListener);
       button2.setOnClickListener(mClickListener);
       button3.setOnClickListener(mClickListener);

然后在 onCreate() 外面写

       OnClickListener mClickListener = new View.OnClickListener() {
              .................
            //your logic.
           switch (v.getId()) {
        case R.id.BtnDisplay:

         break;

        case R.id.BtnSlave:

             break ;
        case R.id.takeashot:
          }
于 2013-09-10T04:31:40.633 回答