无法从活动调用getSupportFragmentManager() [英] Cannot call getSupportFragmentManager() from activity
问题描述
我有其中有一个片段的活动。
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" />
和我想从活动的方法调用从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?
推荐答案
您的活动不会延长<一个href="http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html">FragmentActivity从支持库,因此该方法不是present在超
Your activity doesn't extend FragmentActivity from the support library, therefore the method is not present in the superclass
如果你的目标API 11或以上,你可以使用<一个href="http://developer.android.com/reference/android/app/Activity.html#getFragmentManager%28%29">Activity.getFragmentManager代替。
If you are targeting api 11 or above, you could use Activity.getFragmentManager instead.
这篇关于无法从活动调用getSupportFragmentManager()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!