我正在尝试让 Android 的菜单正常工作
主要活动
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menumenu, menu);
return true;
}
public void myClickHandler(View v)
{
switch(v.getId())
{
case R.id.resetscoreboard:
scoreboardreset();
topText.setText("Scoreboard Has Been Reset!!");
}
}
menumenu.xml
<item
android:id="@+id/resetscoreboard"
android:title="Reset Scoreboard"
android:orderInCategory="1"
android:onClick="myClickHandler">
</item>
你能告诉我为什么当我拉出菜单并单击它时它没有执行任何操作吗?
非常感谢专家@堆栈溢出!
Main Activity
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menumenu, menu);
return true;
}
public void myClickHandler(View v)
{
switch(v.getId())
{
case R.id.resetscoreboard:
scoreboardreset();
topText.setText("Scoreboard Has Been Reset!!");
}
}
menumenu.xml
<item
android:id="@+id/resetscoreboard"
android:title="Reset Scoreboard"
android:orderInCategory="1"
android:onClick="myClickHandler">
</item>
Could you tell me why it does not do anything when I pull up the menu and click on it?
Thanks a lot, experts @ stack overflow!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要定义点击处理程序,而是需要实现:
通过 this 示例来了解 Android 中菜单的具体实现。
Instead of defining click Handler, you need to implement:
Go through this example to get exact idea for the implementation of Menu in Android.
您不应在此处使用
android:onClick
属性。相反,请重写方法
onOptionsItemSelected
。You should not use
android:onClick
attribute here.Instead, override the method
onOptionsItemSelected
.