当我从活动中启动片段时,方法 onCreate(), onViewCreated()会被调用两次。
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chapter_list);
FragmentManager frgManager = getSupportFragmentManager();
if (findViewById(R.id.fl_chapter_detail) != null)
{
mbThreePaneLayout = true;
FragmentChapterList frgChapterList = (FragmentChapterList) frgManager.findFragmentById(R.id.frg_chapter_list);
frgChapterList.setActivateOnItemClick(true);
}
if (savedInstanceState == null)
{
String strSelectedSection = getIntent().getStringExtra(Konstant.KEY_SELECTED_SECTION);
if (((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE) || (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT))
currentActionBar.setTitle(strSelectedSection);
Bundle arguments = new Bundle();
arguments.putString(Konstant.KEY_SELECTED_SECTION, strSelectedSection);
FragmentChapterList frgChapterList = new FragmentChapterList();
frgChapterList.setArguments(arguments);
FragmentTransaction frgTransaction = frgManager.beginTransaction();
frgTransaction.add(R.id.frg_chapter_list, frgChapterList).commit();
}
}
有谁知道为什么会这样?
答案 0 :(得分:2)
解决此问题:
name
属性。有关详细信息,请参阅:InflateException Caused by <fragment> Tag Without a Bound Class