我是程序员的新手,我得到了简单的代码,但它不适合我。
我得到了带有列表的简单菜单,以及带有意图的功能来进行其他活动。
代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_click:
ClickerActivity();
return true;
case R.id.action_upgrades:
UpgradesActivity();
return true;
case R.id.action_warehouse:
WarehouseActivity();
return true;
case R.id.action_postservice:
PostServiceActivity();
return true;
case R.id.action_shop:
ShopActivity();
return true;
case R.id.action_market:
//MarketActivity();
return true;
case R.id.action_garage:
GarageActivity();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void ClickerActivity(View view){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
public void UpgradesActivity(View view){
Intent intent = new Intent(this, UpgradesActivity.class);
startActivity(intent);
}
答案 0 :(得分:0)
因为您的ClickerActivity
函数需要View
输入,在这种情况下不需要,所以删除它
如果您在使用ClickerActivity
的{{1}}中使用XML
,则更好的选择就是在切换案例中复制OnClick
代码
使用此
intent
而不是
public void ClickerActivity(){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
答案 1 :(得分:0)
你也可以找到这样的方式..
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_click:
Intent intent = new Intent(this, Activity.class);
startActivity(intent);
return true;
case R.id.action_upgrades:
Intent intent = new Intent(this, UpgradesActivity.class);
startActivity(intent);
return true;
case R.id.action_warehouse:
WarehouseActivity();
return true;
case R.id.action_postservice:
PostServiceActivity();
return true;
case R.id.action_shop:
ShopActivity();
return true;
case R.id.action_market:
//MarketActivity();
return true;
case R.id.action_garage:
GarageActivity();
return true;
default:
return super.onOptionsItemSelected(item);
}
}