Inflating a view basically just means creating it from an XML file and returning it.
In your specific case, you just need to return your fragment content view from the onCreateView
function. This must be a single view, so if your condition is true and you want 2 views do the following:
Create a
FrameLayout
view yourself programmaticallySomething like:
FrameLayout frameLayout = new FrameLayout(context);
Add the 1st view to your
FrameLayout
after inflating itEither do
frameLayout.addView(inflater.inflate(R.layout.gridpage1,frameLayout,false));
or eveninflater.inflate(R.layout.gridpage1,frameLayout,true);
is enough becausetrue
tells it to add the view to the container.Add the 2nd view to your
FrameLayout
after inflating it- Return the
FrameLayout
from youronCreateView
Addition:
How to save the reference to each view:
Option 1:
View v1 = inflater.inflate(R.layout.gridpage1,frameLayout,false);
this.v1Reference = v1;
frameLayout.addView(v1);
Option 2:
inflater.inflate(R.layout.gridpage1,frameLayout,true);
this.v1Reference = frameLayout.findViewById(...);