"在切换案例下无法使用菜单项中的按钮注销语句。 "
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.sign_out_menu:
AuthUI.getInstance().signOut(this); //NOT REACHABLE
return true;
default:
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
在方法结束时写下这一行 "返回super.onOptionsItemSelected(item);"
答案 1 :(得分:0)
删除方法onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item); // Remove this line
switch(item.getItemId()){
}
}
因为您的代码中有一个return语句,所以return
语句中不属于switch
的所有内容都无法访问
答案 2 :(得分:0)
您可以使用return super.onOptionsItemSelected(item);或完全正确;结束开关盒后,不要忘记休息;声明。
int id = item.getItemId();
switch (id) {
case R.id.id1:
Fragment1 fragment1 = new Fragment1();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(((ViewGroup)getView().getParent()).getId() , fragment1);
fragmentTransaction.commit();
break;
case R.id.id2:
Fragment2 fragment2 = new Fragment2();
FragmentManager fragmentManager1 = getFragmentManager();
FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction();
fragmentTransaction1.replace(((ViewGroup)getView().getParent()).getId() , fragment2);
fragmentTransaction1.commit();
break;
}
return true;