无法从活动调用 getSupportFragmentManager() [英] Cannot call getSupportFragmentManager() from activity

查看:26
本文介绍了无法从活动调用 getSupportFragmentManager()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含片段的活动.

I have an activity which has a fragment.

XML:

 <fragment android:name="com.example.androidcalculator.ResultFragment"
            android:id="@+id/result_fragment"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

我想从 Activity 中的一个方法中调用 ResultFragment 中的一个方法,但是 getSupportFragmentManager不存在":

And I want to call a method from ResultFragment from a method in the Activity, but getSupportFragmentManager "doesn't exist":

FragmentManager fragMan = getSupportFragmentManager();

我该如何解决这个问题?

How can I resolve this?

推荐答案

您的 Activity 不会扩展 FragmentActivity 来自支持库,因此该方法不存在于超类中

Your activity doesn't extend FragmentActivity from the support library, therefore the method is not present in the superclass

如果您的目标是 api 11 或更高版本,您可以使用 Activity.getFragmentManager 代替.

If you are targeting api 11 or above, you could use Activity.getFragmentManager instead.

这篇关于无法从活动调用 getSupportFragmentManager()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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