需要android.support.v4.app.FragmentTransaction [英] android.support.v4.app.FragmentTransaction required

查看:377
本文介绍了需要android.support.v4.app.FragmentTransaction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进入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().

希望这有助于

这篇关于需要android.support.v4.app.FragmentTransaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆