I have faced problem while creating fragments. In my mainActivity i am calling this fragment..
Fragment fr = new Article();
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.container, fr);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
but it is not displaying because instead of given two imports I have to add the supprot.v4 one and
import android.app.FragmentManager;//correct one
import android.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;// wrong one..
import android.support.v4.app.FragmentTransaction;
and in the fragment class i have to import this
import android.app.Fragment;
//instead of the given below..
import android.support.v4.app.Fragment;
Know the problem is solved.. But i am curious about the difference between them. And what is the better way of using fragment. I have created a
MainActivity which extends Activity
and in that class i am displaying fragments.
One of my colleague told me to extends mainActivity from Fragment
. Otherwise i will have to face a lot of problem. Tell me which is the proper way to use . Or what are the benefits or disadvantage of extending mainActivity from Activity
while using Fragments
...
Thanks in Advance..