如何使子行动 [英] how to make action on submenu
本文介绍了如何使子行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ArrayList<String> emplist = new ArrayList<String>();
//Inside the array I add list of employee that I query from DB
SubMenu empMenu = menu.addSubMenu("Employee's Map").setIcon(R.drawable.group);
for (int i = 0; i < emplist.size(); i++) {
empMenu.add(EMPLOYEE, i, i, emplist.get(i));
}
用户可以选择员工的名字,那么我将履行我的结果preFER选项。
所以,我的问题是怎样才能得到其中涉及到选择了 onCreateOptionsMenu(菜单菜单)使用用户的条目标识
谢谢您的建议。
推荐答案
您可以覆盖<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onOptionsItemSelected%28android.view.MenuItem%29\"相对=nofollow> onOptionsItemSelected
在你的活动获得哪个菜单项是通过调用选择方法 getItemId
在菜单项
参数。下面是一个示例code。
You can override onOptionsItemSelected
methods in your Activity to get which menu item is selected by calling getItemId
on the menuItem
argument. Following is a sample code.
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
// process with the item id of user selected menu.
// ...
return true
}
这篇关于如何使子行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文