Two fragment deployment methods in android
1. Static class deployment method:
Layout. xml
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
Android: id = "@ + id/fragment1"
Android: name = "com. example. filedirtest. Fragment2"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "0.20"/>
Class:
Import android. app. Fragment; // note that this fragment is imported here.
Public static class Selffragment extends Fragment {
Public Selffragment (){
}
@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ){
// TODO Auto-generated method stub
View root = inflater. inflate (R. layout. prefrence_fragment, container, false );
Return root;
}
}
2. Dynamic Creation:
Fragment class:
Public class ExampleFragment extends Fragment {
@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ){
// TODO Auto-generated method stub
View rootView = inflater. inflate (R. layout. fragment_layout, container, false );
Return rootView;
}
}
Create in activity;
ExampleFragment fragment = new ExampleFragment ();
Getsuppfrfragmentmanager (). beginTransaction ()
. Add (R. id. fragmentContainer, fragment). commit ();