开发者

how to make action on submenu

开发者 https://www.devze.com 2023-03-19 09:04 出处:网络
ArrayList<String> emplist = new ArrayList<String>(); //Inside the array I add list of employee that I query from DB
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));
}

I prefer option for user that can select name of employee then I will perform result. So, my question is how can I get the itemId which relate to user's selecte开发者_JAVA技巧d to use in onCreateOptionsMenu(Menu menu) Thank you for your suggestion.


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消