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
.
Asked
Active
Viewed 325 times
0
-
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 Answers
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...
-
but I more than one dynamic layouts from which I want to select any one of them... – Akshay Feb 17 '14 at 07:54
-
-
-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
-
fragments wont allow constructor having variables in it, we can only use default constructor. – Syed Raza Mehdi Aug 20 '14 at 07:17