Suppose I have a fragment that has a listview, and I want to use this fragment dynamically in the code. But for fragments it is impossible to use the designer. How do I pass in a Cursor fragment for example or another class object.

  • 2
    use setters / getters - Vladyslav Matviienko

1 answer 1

Why not?

public class MyFragment extends Fragment { protected Object mObj; public static Fragment newInstance(Object obj) { MyFragment fragment = new MyFragment(); fragment.mObj = obj; return fragment; } ............. } 

Well, call, respectively, MyFragment.newInstance(obj)