0

スマートフォン(1 ペイン レイアウト)とタブレット(2 ペイン レイアウト)に対応したアプリケーションを開発しようとしています。私のアプリは次のように表示されます。

断片
(ソース: android10.org )

Google 開発者のウェブサイトで利用可能な例を使用しました。

この例は正常に動作します。しかし、私のアプリでは、で別のレイアウトを使用する必要がありますWebView fragment。で選択された各要素ListView fragmentは、特定のレイアウトを右側のフラグメントに表示します。

これは、要素がクリックされたときに呼び出される私のコードです:

public void onArticleSelected(int position) {
    // The user selected the headline of an article from the
    // HeadlinesFragment

    // Capture the article fragment from the activity layout
    BodyFragment articleFrag = (BodyFragment) getSupportFragmentManager().findFragmentById(R.id.body_fragment);

    if (articleFrag != null) {
        // If article frag is available, we're in two-pane layout...

        // Call a method in the ArticleFragment to update its content
        articleFrag.updateArticleView(position);

    } else {
        // If the frag is not available, we're in the one-pane layout and
        // must swap frags...

        // Create fragment and give it an argument for the selected
        // article
        BodyFragment newFragment = new BodyFragment();

        Bundle args = new Bundle();
        args.putInt(BodyFragment.ARG_POSITION, position);
        newFragment.setArguments(args);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this
        // fragment,
        // and add the transaction to the back stack so the user can
        // navigate back
        transaction.replace(R.id.fragment_container, newFragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
    }
}

どうすれば作れますか?レイアウトをフラグメントに動的に置き換えることを考えましたが、それは不可能です。

誰かが解決策を持っていますか?

前もって感謝します

4

0 に答える 0