0

I have created the class which extends Fragment which creates the RelativeLayout.I want to know how to pass that dynamically created RelativeLayout to the another fragment containing FrameLayout and set that RelativeLayout to that FrameLayout.

Niklas B.
  • 92,950
  • 18
  • 194
  • 224
Akshay
  • 6,029
  • 7
  • 40
  • 59
  • what you can do is make a variable of the data type you required in the fragment and a setter function in it set that variable this is how we can do this, if you want to pass int, float or boolean you can use bundle and the setArguments method. – Syed Raza Mehdi Aug 20 '14 at 08:26

2 Answers2

1

Why creating the layout outside the fragment? that's why fragments have onCreaveView & onViewCreated methods in their lifecycle.

I would suggest you to pass a STATE variable (int,string) to the fragment using Bundle, and on the onCreateView method get the state in build the view according to it.

You can find simple example how to pass bundle and use it inside the fragment here

If you find yourself must pass a view to fragment you can use 3rd class which will hold it. But that's really not the right way...

Community
  • 1
  • 1
Udi Oshi
  • 6,787
  • 7
  • 47
  • 65
-1

I haven't try it yet but it might work

class CustomFragment extends Fragment{

    RelativeLayout relativeView;

    CustomFragment(RelativeLayout view){
        relativeView = view;
    }

    onCreateView(){
       //inflate layout and get FrameLayout
       frameLayout.addView(relativeView);
    }
}

and your RelativeLayout

RelativeLayout r = new RelativeLayout(context);
// custom it as you wish
CustomFragment fragment = new CustomFragment(r);
vfongmala
  • 185
  • 1
  • 2
  • 11