FragmentManager和androidx FragmentManager [英] FragmentManager and androidx FragmentManager

查看:1135
本文介绍了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.FragmentManagerinstead of a android.app.FragmentManager.

如何处理androidX中的旧"片段?

How can I work with "old" fragments in androidX?

推荐答案

  1. 将此添加到依赖项: implementation 'androidx.appcompat:appcompat:1.0.2'.
  2. 添加此内容:import androidx.fragment.app.FragmentTransaction;.
  3. 切换活动范围从Activity扩展到AppCompatActivity.
  4. getFragmentManager()更改为getSupportFragmentManager().
  1. Add this to dependencies: implementation 'androidx.appcompat:appcompat:1.0.2'.
  2. Add this: import androidx.fragment.app.FragmentTransaction;.
  3. Switch your activity extends from Activity to AppCompatActivity.
  4. Change from getFragmentManager() to getSupportFragmentManager().

这将解决您的问题.

这篇关于FragmentManager和androidx FragmentManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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