Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用清单文件创建了一个子菜单。我的子菜单中有四个文本字段。我想知道用户点击了哪个子菜单项。我知道菜单项的 switch case item.getItemId 条件。但我想知道如何检查用户点击了哪个子菜单。谢谢你的帮助
您可以将子菜单项的 ID 保存到变量中。例如:
int item; @Override public void onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.something: { this.item = something; return true; } }
现在变量 item 包含所选项目的 id。