我所拥有的是有一个菜单选项,可以说数字猜谜游戏,当它被按下时,它会提供一个祝词。我想要它做的是,当它被按下时,它将打开一个存在于项目中的类。如果相关,则此项目称为InputEvent.java。我该怎么做呢?这是我当前打开菜单并在按下时显示吐司的代码:
//******** THE MENUS ***********//
//Create the OPTIONS menu on start up
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); //To inflate the xml
inflater.inflate(R.menu.walk_options_menu,menu); //Inflate the options
return true;
}
//Respond to item selected on OPTIONS MENU
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.NumGame:
Toast.makeText(this, "Twitter", Toast.LENGTH_SHORT).show();
return true;
default
:
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
试试这个:
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.NumGame:
//Toast.makeText(this, "Twitter", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, InputEvent.class);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}