How to display an existing ListFragment in a DialogFragment

前端 未结 4 1068
一个人的身影
一个人的身影 2020-12-16 01:44

I have the following problem:

I have an exisiting ListFragment, but I would like to display this as a dialog.

My first approach was to create a

4条回答
  •  不思量自难忘°
    2020-12-16 02:17

    What works for me is

    1) in xml layout for your DialogFragment called, let's say, DialogFragmentwWithListFragment specify ListFragment class
    E.g. dialog_fragment_with_list_fragment.xml :

    
            
    
    

    2) in 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) invoke DialogFragmentwWithListFragment as regular DialogFragment:

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


    Hope, it helps.

提交回复
热议问题