内内菜单菜单子?菜单

2023-09-04 06:43:21 作者:上古神剑都你没你贱

在pressing菜单按钮,我有两个选择:加入&功放;更多。 在点击更多,我有3个选项:组织,出口及放大器;出口 在单击组织的,我想其他的5个选项。

在点击更多的让我的子菜单。但我想其他的5个选项上点击organize.How做我继续???

我的code的部分如下: XML文件-------------------------------

 < XML版本=1.0编码=UTF-8&GT?;
  <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

   <项目
    机器人:ID =@ + ID /多
    机器人:标题=@字符串/ moreMenu
    机器人:图标=@可绘制/图标>
    <菜单>
        <项目机器人:ID =@ + ID /组织
        机器人:标题=@字符串/组织/>

        <项目机器人:ID =@ + ID /导出
        机器人:标题=@字符串/导出/>
    < /菜单>
   < /项目>

   <项目
    机器人:ID =@ + ID /加
    机器人:标题=@字符串/ addMenu
    机器人:图标=@可绘制/添加/>
   < /菜单>
 
菜单 内芯图片

Java的-------------------------

 进口android.app.Activity;
进口android.os.Bundle;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.widget.Toast;

公共类TodoList的延伸活动{
 菜单中的菜单;
  公共无效的onCreate(包savedInstanceState){
         super.onCreate(savedInstanceState);
         的setContentView(R.layout.todolist);

   }



  公共布尔onCreateOptionsMenu(功能菜单){
         super.onCreateOptionsMenu(菜单);
         。getMenuInflater()膨胀(R.layout.categorymenu,菜单);

         返回true;


     }
   公共布尔onOptionsItemSelected(菜单项项){
         开关(item.getItemId()){

         案例R.id.more:
               Toast.makeText(这一点,你pressed更多,Toast.LENGTH_LONG).show();
//(需要从这里做什么)
                    返回true;

         案例R.id.add:
           Toast.makeText(这一点,你pressed添加,Toast.LENGTH_LONG).show();
          返回true;
           }
         返回false;
         }
   公共布尔prepareOptionsMenu(功能菜单)在{
                   返回true;
     }
  }
 

解决方案

正如在的创建菜单子菜单不能包含子菜单。

您可以点击选项菜单项后显示的上下文菜单。 这可能表明你的五个选项浮动视图的屏幕上方。

您必须覆盖onCreateContextMenu创建一个文本菜单,我认为你必须在onOptionsItemSelected方法手动调用文本菜单。有关如何创建上下文菜单中看到此段落在上面提到的文章。

要打开文本菜单,你可以叫 openContextMenu 在你的活动。您可能需要注册的菜单项之前,让您的活动,找到正确的上下文菜单。

On pressing menu button , I have 2 options : Add & more. On click of more i have 3 options : Organize ,Export & Exit On click of Organize i want other 5 options.

On click of more i get my submenu. But i want other 5 options on click of organize.How do i proceed???

My code in parts is as follows : XML file-------------------------------

<?xml version="1.0" encoding="utf-8"?>   
  <menu xmlns:android="http://schemas.android.com/apk/res/android">

   <item    
    android:id="@+id/more"    
    android:title="@string/moreMenu"    
    android:icon="@drawable/icon">
    <menu>
        <item android:id="@+id/Organize"
        android:title="@string/Organize" />

        <item android:id="@+id/Export"
        android:title="@string/Export" />
    </menu>  
   </item> 

   <item    
    android:id="@+id/add"    
    android:title="@string/addMenu"  
    android:icon="@drawable/add"/>
   </menu>

Java-------------------------

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class ToDoList extends Activity {
 Menu menu;
  public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.todolist); 

   }



  public boolean onCreateOptionsMenu(Menu menu) {   
         super.onCreateOptionsMenu(menu);   
         getMenuInflater().inflate(R.layout.categorymenu, menu);

         return true; 


     }  
   public boolean onOptionsItemSelected(MenuItem item) {   
         switch (item.getItemId()) { 

         case R.id.more:   
               Toast.makeText(this, "You pressed more!", Toast.LENGTH_LONG).show();
//(What needs to be done from here)
                    return true;

         case R.id.add:
           Toast.makeText(this, "You pressed add!", Toast.LENGTH_LONG).show();
          return true;
           }
         return false;
         }
   public boolean onPrepareOptionsMenu(Menu menu) {   
                   return true;   
     }
  }

解决方案

As can be seen in Creating Menus sub menus can not contain sub menus.

You could show a Context menu after clicking on the item in the options menu. This could show your five more options in a floating view above the screen.

You have to overwrite the onCreateContextMenu to create a ContextMenu and I think you have to call the contextMenu manually in the onOptionsItemSelected method. For resources on how to create the context menu see this paragraph in the article mentioned above.

To open the ContextMenu you can call openContextMenu in your Activity. You may need to register the menuitem before to enable your activity to find the correct context menu.