This took me a while to understand.
But here's the break down.
Before Honeycomb the usual navigation was from one activity to the next.
With fragments, it was possible for several user components to exist within a single activity.
Each fragment involves a single XML file with a java class.
Create an XML file with 2 relativelayout components.
Now create 2 XML files with a design/background of your choice and create 2 java class files coresponding to them.
public class Fragmentone extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v=inflater.inflate(R.layout.fragmentonelayout,container,false);
return v;
}
}
This is what your java class will look like.
You'll need onCreateView and you'll have to return the view with the inflated XML file.
Now in your main activity, you'll have to access the class.
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
Fragmentone f1=new Fragmentone();
ft.add(R.id.fr1_id, f1);
ft.commit();
Use a fragment manager, and assign it to a fragmenttransaction after using begintransaction()
Then create a object of your fragment class, to invoke the inflater.
Then add the realtivelayout id, with your class object.
Finally commit.
But here's the break down.
Before Honeycomb the usual navigation was from one activity to the next.
With fragments, it was possible for several user components to exist within a single activity.
Each fragment involves a single XML file with a java class.
Create an XML file with 2 relativelayout components.
Now create 2 XML files with a design/background of your choice and create 2 java class files coresponding to them.
public class Fragmentone extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v=inflater.inflate(R.layout.fragmentonelayout,container,false);
return v;
}
}
This is what your java class will look like.
You'll need onCreateView and you'll have to return the view with the inflated XML file.
Now in your main activity, you'll have to access the class.
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
Fragmentone f1=new Fragmentone();
ft.add(R.id.fr1_id, f1);
ft.commit();
Use a fragment manager, and assign it to a fragmenttransaction after using begintransaction()
Then create a object of your fragment class, to invoke the inflater.
Then add the realtivelayout id, with your class object.
Finally commit.