Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android片段-将不同的布局放入片段中_Android_Android Layout_Android Fragments - Fatal编程技术网

Android片段-将不同的布局放入片段中

Android片段-将不同的布局放入片段中,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我正在尝试开发一个与智能手机(单窗格布局)和平板电脑(双窗格布局)兼容的应用程序。我的应用程序显示如下所示: (来源:) 我使用了中提供的示例 这个例子很好用。但是对于我的应用程序,我需要在WebView片段中使用不同的布局。在ListView fragment中选择的每个元素在右侧片段中显示特定的布局 这是我在单击元素时调用的代码: public void onArticleSelected(int position) { // The user selected the headl

我正在尝试开发一个与智能手机(单窗格布局)和平板电脑(双窗格布局)兼容的应用程序。我的应用程序显示如下所示:


(来源:)

我使用了中提供的示例

这个例子很好用。但是对于我的应用程序,我需要在
WebView片段中使用不同的布局。在
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();
    }
}
我该怎么做?我想动态地将布局替换为片段,但这是不可能的

有人有解决办法吗


提前感谢

只需在列表上为webview保留一个片段,片段单击(位置)调用您想要查看的内容我的代码在上面可见。我不知道在哪里可以设置要在片段中使用的布局:(