当我从菜单中选择一个选项时,我正在尝试加载活动:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_flash:
Intent intent = new Intent(this, FlashActivity.class);
this.startActivity(intent);
break;
case R.id.menu_color:
Intent intent = new Intent(this, FlashActivity.class);
this.startActivity(intent);
break; break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
但它一直给我意图错误
答案 0 :(得分:0)
Intent intent = new Intent(youractivity.this, FlashActivity.class);
startActivity(intent);
更改为上面的代码......
答案 1 :(得分:0)
确保FlashActivity在清单文件中声明。然后试试..
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_flash:
openFlashmenu();
return true;
case R.id.menu_color:
openFlashmenu();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void openFlashmenu(){
Intent intent = new Intent(this, FlashActivity.class);
this.startActivity(intent);
}
答案 2 :(得分:0)
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.menu_flash:
Intent intent = new Intent(this, FlashActivity.class);
startActivity(intent);
return true;
}
return false;
答案 3 :(得分:0)
改变:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
Intent intent = new Intent(this, FlashActivity.class);
this.startActivity(intent);;
return true;
case R.id.item2:
Intent intent = new Intent(this, FlashActivity.class);
this.startActivity(intent);
return true;
default:
return super.onContextItemSelected(item);
}
}
答案 4 :(得分:0)
您是否在清单文件中声明了FlashActivity?
如果没有,请将其添加到您的清单中:
<activity
android:name=".FlashActivity" >
</activity>