ListFragment支持库GetSupportFragmentManager未定义 [英] ListFragment Support Library GetSupportFragmentManager undefined

查看:57
本文介绍了ListFragment支持库GetSupportFragmentManager未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表片段(导入v4支持库,构建目标是2.3.3 api 11)并且以下代码中的问题在目标为3.0且我未使用该库时仍能正常工作.

I have a list Fragment (importing the v4 support library, build target is 2.3.3 api 11) and the following problem in my code that was working fine when the target was 3.0 and I didn't use the library.

Fragment frag1 = new ExampleFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.contentframe, frag1);
ft.commit();

现在我得到了

"Type mismatch: cannot convert from ExampleFragment to Fragment"

它告诉我将"Fragment"更改为ExampleFragment(例如)

and it tells me to change the "Fragment" to ExampleFragment (e.g.)

ExamplesFragment frag1 = new ExamplesFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.contentframe, frag1);
ft.commit();

然后我有一个问题,即ft.replace命令有一个错误:

Then I have a problem that the ft.replace command has an error:

The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Fragment_PVAnn)

它告诉我将第一行中的ExamplesFragment改回Fragment,这样圆就绕着转了

and it tells me to change the ExamplesFragment in the first line back to just Fragment and so the circle goes round and around

推荐答案

您应该使用

getActivity().getSupportFragmentManager()

如果这仍然给您带来问题,则请确保您的 Activity扩展了FragmentActivity .

If that is still giving you problems, then makre sure that your Activity extends FragmentActivity.

如果那仍然给您带来麻烦,

If that is still giving you problems,

  1. 删除所有所有
  2. 使用 Ctrl + Shift + O
  3. 重新导入
  4. 在每次名称冲突时,请确保从 support.v4.* 导入,不是 android.* .
  1. Delete all of your imports,
  2. Re-import with Ctrl + Shift + O, and
  3. On every name clash, make sure you import from support.v4.*, not android.*.

这篇关于ListFragment支持库GetSupportFragmentManager未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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