android – 如何在DialogFragment中显示现有的ListFragment

我有以下问题:

我有一个现成的ListFragment,但我想显示一个对话框.

我的第一个方法是创建一个DialogFragment,该对话框必须在其内部列出ListFragment,但是显然目前不可能将片段放入片段.

扩展DialogFragment而不是ListFragment也是不可能的,因为大量使用ListFragment方法.

有没有办法做到这一点?

解决方法

我有用的是
1)在您的DialogFragment的xml布局中,我们来说,DialogFragmentwWithListFragment指定ListFragment类
例如. dialog_fragment_with_list_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <fragment
             android:id="@+id/flContent"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:padding = "10dp"
             class="com.xxx.yyy.DialogFragmentwWithListFragment " />
</LinearLayout>

2)在DialogFragmentwWithListFragment inflate dialog_fragment_with_list_fragment.xml

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
    return inflater.inflate(R.layout.dialog_fragment_with_list_fragment,null);
}

3)调用DialogFragmentwWithListFragment作为常规DialogFragment:

DialogFragmentwWithListFragment dialogFragment = DialogFragmentwWithListFragment  .newInstance();
 dialogFragment.setRetainInstance(true);
 dialogFragment.show(getFragmentManager(),"tag");

希望,它有帮助.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...