Best practice for instantiating a new Android Fragment

前端 未结 13 1549
暖寄归人
暖寄归人 2020-11-21 04:38

I have seen two general practices to instantiate a new Fragment in an application:

Fragment newFragment = new MyFragment();

and

<         


        
13条回答
  •  自闭症患者
    2020-11-21 05:09

    I believe I have a much simpeler solution for this.

    public class MyFragment extends Fragment{
    
       private String mTitle;
       private List mObjects;
    
       public static MyFragment newInstance(String title, List objects)
       MyFragment myFrag = new MyFragment();
       myFrag.mTitle = title;
       myFrag.mObjects = objects;
       return myFrag;
       }
    

提交回复
热议问题