需要android.support.v4.app.FragmentTransactionsupport、android、FragmentTransaction、app

2023-09-08 09:29:54 作者:偏执i

进入code是这样的:

entering in code like this:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

想出了这个错误android.support.v4.app.FragmentTransaction交易= 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();

和我在延伸FragmentActivity我的主要活动打字这一点。有谁知道为什么吗?我已经包括:

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;

修改

 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();

改变getSupportFragmentManager()来getFragmentManager()要求我DescriptionFragment改变android.app.Fragment ...任何想法?

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

推荐答案

通过getSupportFragmentManager()你所得到的supportLibrary fragmentManager而不是系统fragmentManager的。所以,你的supportlibrary的交易工作。

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

这就是为什么你需要添加这些进口并使用android.support.v4.app的原因。

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

如果你想获得fragmentManager只是尝试使用getFragmentManager(),而不是getSupportFragmentManager()系统

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

希望这有助于