Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.support.v4.app.FragmentTransaction required

Tags:

java

android

entering in code like this:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

comes up with this error "android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();" and has this as a quick fix which does in fact remove the error:

android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

and i am typing this in my main activity which extends FragmentActivity . Does anybody know why? i have included:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

EDIT

 DescriptionFragment fragment = new DescriptionFragment();
            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.pager, fragment);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            ft.commit();

changing getSupportFragmentManager() to getFragmentManager() requires me to change DescriptionFragment to android.app.Fragment...any ideas?

like image 425
android_man1 Avatar asked Jul 01 '13 06:07

android_man1


3 Answers

With getSupportFragmentManager() you are getting the supportLibrary fragmentManager instead of the systems fragmentManager. So you are working with a transaction of the supportlibrary.

This is the reason why you need to add all these imports and use android.support.v4.app.

If you want to get the systems fragmentManager just try to use getFragmentManager() instead getSupportFragmentManager().

Hope this helps

like image 108
jaumebd Avatar answered Nov 16 '22 17:11

jaumebd


try this

public class DescriptionFragment extends android.support.v4.app.Fragment

instead of simply Fragment.

like image 23
johndpope Avatar answered Nov 16 '22 16:11

johndpope


Have you import android.support.v4.jar file to your project??

like image 2
Shani Goriwal Avatar answered Nov 16 '22 16:11

Shani Goriwal