0

アクティビティからフラグメントを開始すると、メソッドonCreate()onViewCreated( ) が 2 回呼び出されます。

これが私のコードです:

@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();
    }
}

なぜそれが起こっているのか誰にも分かりますか?

4

1 に答える 1

2

これを修正するには:

  • フラグメントのタグのタイプを <fragment /> から <FrameLayout /> などのプレースホルダーに変更します。
  • 属性を削除しnameます。

詳細については、以下を参照してください:クラスがバインドされていない <fragment> タグが原因で InflateException が発生する

于 2013-02-23T05:47:53.237 に答える