如何從onOptionsItemsSelected啓動片段?操作欄啓動片段
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_support:
Fragment f = new SupportFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(android.R.id.content, f).commit();
Toast display = Toast.makeText(this, "Settings", 10);
display.show();
case R.id.action_guide:
Toast display1 = Toast.makeText(this, "Guide", 10);
display1.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
我試圖啓動支持片段。
感謝
https://www.dropbox.com/s/4vnzxmypv6hggvh/error.txt – user2229747
顯示java.lang.NullPointerException 02-25 13:06 :37.231:W/System.err(27967):\t at openday.SupportFragment.onCreate(SupportFragment.java:18) 查看SupportFragment.java類中的第18行有一個nullPointerException,或編輯您的帖子併發布整個代碼來獲得t他的問題解決了,但這似乎是另一個問題 –
謝謝,發現問題! – user2229747