FragmentManager和androidx FragmentManager [英] FragmentManager and androidx FragmentManager
本文介绍了FragmentManager和androidx FragmentManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在使用androidX的应用中进行设置.
I'm trying to setup in my app that is using androidX.
我的问题是,当我尝试使用PlaceAutocompleteFragment时遇到错误,因为它是来自android.app.fragment
的片段,而我的父片段是androidx片段:androidx.fragment.app.Fragment
,因此它使用androidx.fragment.app.FragmentManager
而不是
My problem is that when I try to work with PlaceAutocompleteFragment I get errors because it is a fragment from android.app.fragment
and my parent fragment is an androidx fragment: androidx.fragment.app.Fragment
so it uses a androidx.fragment.app.FragmentManager
instead of a android.app.FragmentManager
.
如何处理androidX中的旧"片段?
How can I work with "old" fragments in androidX?
推荐答案
- 将此添加到依赖项:
implementation 'androidx.appcompat:appcompat:1.0.2'
. - 添加此内容:
import androidx.fragment.app.FragmentTransaction;
. - 切换活动范围从
Activity
扩展到AppCompatActivity
. - 从
getFragmentManager()
更改为getSupportFragmentManager()
.
- Add this to dependencies:
implementation 'androidx.appcompat:appcompat:1.0.2'
. - Add this:
import androidx.fragment.app.FragmentTransaction;
. - Switch your activity extends from
Activity
toAppCompatActivity
. - Change from
getFragmentManager()
togetSupportFragmentManager()
.
这将解决您的问题.
这篇关于FragmentManager和androidx FragmentManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文