Bart222 Bart222 - 1 year ago 87
Android Question

Two layouts in Fragment

I am an amateur in Android. Is it possible to add second layout in Fragment?
For example :

View1 view1 = inflater.inflate(R.layout.b, container, false);

public class c extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.a, container, false);

Answer Source

What you can do is create one xml and ad to your view and inflate it like this

View view = inflater.inflate(R.layout.main, container, false);

Then goes to your main.xml and include your two layouts using

 < include >layout-1 < /include >

 < include >layout-2 < /include >

or you can dynamically inflate this 2 layouts and add to your main view

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download