The fragment without UI can only be add within the activity programmatically.
For this we have different variation of add method available.Use
public abstract FragmentTransaction add (Fragment frag, String tag)
frag: fragment we
want to add in activity
tag: unique ID for identification usually the name of fragment.
This method add the fragment in activity .As there is no UI
so onCreateView () implementation is not required.
Code snippet:
FragmentManager fragmentManager =
getFragmentManager();
FragmentTransaction
fragmentTransaction = fragmentManager
.beginTransaction();
// creating a
fragment object
Fragmentone
fragmentone = new Fragmentone();
fragmentTransaction.add(fragmentone,"fragmentone");
Comments
Post a Comment