<bdo id='avwQc'></bdo><ul id='avwQc'></ul>

  • <small id='avwQc'></small><noframes id='avwQc'>

    <legend id='avwQc'><style id='avwQc'><dir id='avwQc'><q id='avwQc'></q></dir></style></legend>

    <i id='avwQc'><tr id='avwQc'><dt id='avwQc'><q id='avwQc'><span id='avwQc'><b id='avwQc'><form id='avwQc'><ins id='avwQc'></ins><ul id='avwQc'></ul><sub id='avwQc'></sub></form><legend id='avwQc'></legend><bdo id='avwQc'><pre id='avwQc'><center id='avwQc'></center></pre></bdo></b><th id='avwQc'></th></span></q></dt></tr></i><div id='avwQc'><tfoot id='avwQc'></tfoot><dl id='avwQc'><fieldset id='avwQc'></fieldset></dl></div>
    <tfoot id='avwQc'></tfoot>

      1. 处理菜单项点击事件 - Android

        时间:2023-08-31
        • <small id='xoocK'></small><noframes id='xoocK'>

              <tbody id='xoocK'></tbody>
              <legend id='xoocK'><style id='xoocK'><dir id='xoocK'><q id='xoocK'></q></dir></style></legend>
              <tfoot id='xoocK'></tfoot>
              • <bdo id='xoocK'></bdo><ul id='xoocK'></ul>

                <i id='xoocK'><tr id='xoocK'><dt id='xoocK'><q id='xoocK'><span id='xoocK'><b id='xoocK'><form id='xoocK'><ins id='xoocK'></ins><ul id='xoocK'></ul><sub id='xoocK'></sub></form><legend id='xoocK'></legend><bdo id='xoocK'><pre id='xoocK'><center id='xoocK'></center></pre></bdo></b><th id='xoocK'></th></span></q></dt></tr></i><div id='xoocK'><tfoot id='xoocK'></tfoot><dl id='xoocK'><fieldset id='xoocK'></fieldset></dl></div>

                1. 本文介绍了处理菜单项点击事件 - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想创建一个在单击菜单项后启动新活动的意图,但我不确定如何执行此操作.我一直在阅读 android 文档,但我的实现不正确..一些正确方向的指导会有所帮助.我在下面列出了我的代码并注释掉了我的问题区域,我认为我调用了错误的方法.

                  I want to create an intent that starts a new activity once a Menu Item is clicked, but I'm not sure how to do this. I've been reading through the android documentation, but my implementation isn't correct..and some guidance in the right direction would help. I've listed my code below and commented out my problem areas, I think I'm invoking the wrong method.

                  package com.jbsoft.SimpleFlashlight;
                  
                  import android.app.Activity;
                  import android.content.Intent;
                  import android.os.Bundle;
                  import android.view.*;
                  import android.view.MenuItem.OnMenuItemClickListener;
                  import android.widget.Button;
                  import android.widget.Toast;
                  
                  public class SimpleFlashLightActivity extends Activity {
                  
                  
                    Button GreenButton;   // Declare instances of buttons to use later
                    Button BlueButton;
                  
                    private static final int OK_MENU_ITEM = Menu.FIRST;
                  
                    /** Called when the activity is first created. */
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.main);
                  
                      BlueButton = (Button) findViewById(R.id.bluebutton);
                      BlueButton.setOnClickListener(new View.OnClickListener() {
                  
                        public void onClick(View v) {
                  
                          //Display msg when user clicks Blue Button
                          showColorChangeMsg();
                  
                          // Switch Activities on click
                          Intent blueintent = new Intent(SimpleFlashLightActivity.this,
                                                         BlueFlashLightActivity.class);
                          startActivity(blueintent);
                  
                        }
                      });
                      //Install listener for second button
                      GreenButton = (Button) findViewById(R.id.greenbutton);
                      GreenButton.setOnClickListener(new View.OnClickListener() {
                  
                        public void onClick(View v) {
                  
                          // Display msg when user clicks Green Button
                          showColorChangeMsg();
                  
                          Intent greenintent = new        Intent(SimpleFlashLightActivity.this,
                                                                 GreenFlashLightActivty.class);
                          startActivity(greenintent);
                  
                        }
                      });
                  
                      ;
                  
                      /**************************************************************************************/
                  
                      // Method Declarations // THIS IS WHERE I'M HAVING A PROBLEM
                  
                      MenuItem AddColorButton = (MenuItem)findViewById(R.id.menu_insert);
                  
                      boolean onOptionsItemSelected(AddColorButton) {
                        Intent intent = new  Intent(SimpleFlashLightActivity.this,
                                                    BlueFlashLightActivity.class);
                        startActivity(intent);
                        return true;
                        ;
                      };
                      /****************************************************************************************/
                  
                    }
                    private void showColorChangeMsg()
                    {
                      Toast msgtoast = Toast.makeText(this.getBaseContext(), "SWITCH COLOR!",
                                                      Toast.LENGTH_LONG);
                      msgtoast.show();
                    }
                    private void showMsg(String msg) {
                      Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
                      toast.show();
                    }
                  
                    public boolean onCreateOptionsMenu(Menu menu) {
                      super.onCreateOptionsMenu(menu);
                      MenuInflater mi = getMenuInflater();
                      mi.inflate(R.menu.list_menu, menu);
                      return true;
                  
                    }
                  
                    @Override
                    public boolean onOptionsItemSelected(MenuItem item) {
                      switch (item.getItemId()) {
                      case OK_MENU_ITEM:
                        showMsg("OK");
                        break;
                      }
                      return super.onOptionsItemSelected(item);
                    }
                  
                  }
                  

                  推荐答案

                  创建菜单的简单代码

                  @Override
                  public boolean onCreateOptionsMenu(Menu menu) {
                      MenuInflater inflater = getMenuInflater();
                      inflater.inflate(R.menu.game_menu, menu);
                      return true;
                  }
                  

                  菜单项选择的简单代码

                  @Override
                  public boolean onOptionsItemSelected(MenuItem item) {
                      // Handle item selection
                      switch (item.getItemId()) {
                      case R.id.new_game:
                          newGame();
                          return true;
                      case R.id.help:
                          showHelp();
                          return true;
                      default:
                          return super.onOptionsItemSelected(item);
                      }
                  }
                  

                  您可以从下面的链接中找到更多详细信息..

                  You can find more detail from below link..

                  菜单

                  菜单资源

                  这篇关于处理菜单项点击事件 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检测ios中的通话事件 下一篇:Android 应用上的自定义事件监听器

                  相关文章

                  最新文章

                2. <legend id='MyPfX'><style id='MyPfX'><dir id='MyPfX'><q id='MyPfX'></q></dir></style></legend>
                  <i id='MyPfX'><tr id='MyPfX'><dt id='MyPfX'><q id='MyPfX'><span id='MyPfX'><b id='MyPfX'><form id='MyPfX'><ins id='MyPfX'></ins><ul id='MyPfX'></ul><sub id='MyPfX'></sub></form><legend id='MyPfX'></legend><bdo id='MyPfX'><pre id='MyPfX'><center id='MyPfX'></center></pre></bdo></b><th id='MyPfX'></th></span></q></dt></tr></i><div id='MyPfX'><tfoot id='MyPfX'></tfoot><dl id='MyPfX'><fieldset id='MyPfX'></fieldset></dl></div>

                    1. <small id='MyPfX'></small><noframes id='MyPfX'>

                      • <bdo id='MyPfX'></bdo><ul id='MyPfX'></ul>

                      <tfoot id='MyPfX'></tfoot>