我在Activity中添加了菜單,但是點擊菜單的任何選項卡都不好用,下面是我的Activity類和菜單類。
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>
大家幫我看不看代碼出現了問題嗎?萬分感謝!
除了定義click Handler,還要實現:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.resetscoreboard:
scoreboardreset();
topText.setText("Scoreboard Has Been Reset!!");
break;
default:
break;
}
return true;
}