简体   繁体   English

类型不匹配。 必需:片段,找到:PlaceAutocompleteFragment

[英]Type mismatch. Required: Fragment, Found: PlaceAutocompleteFragment

I bumped into a 我碰到一个

Duplicate ID, tag null, or parent id with another fragment for placeAutocompleteFragment 重复的ID,标签null或父ID,以及placeAutocompleteFragment的另一个片段

error, and so i followed this solution to try and fix it by adding the placeAutocompleteFragment via a fragment transaction using the childFragmentManager 误差,所以我也跟着此溶液 ,试图通过经由使用一个片段交易添加placeAutocompleteFragment修复它childFragmentManager

fragment class onCreateView 片段类onCreateView

val fm: FragmentManager = childFragmentManager
var placeAutocompleteFragment: PlaceAutocompleteFragment? = fm.findFragmentByTag("placeAutocompleteFragment") as PlaceAutocompleteFragment?

if (placeAutocompleteFragment == null){
    placeAutocompleteFragment = PlaceAutocompleteFragment()
    fm.beginTransaction().add(R.id.address_layout, placeAutocompleteFragment, "placeAutocompleteFragment").commit()
}

.xml .xml

<android.support.constraint.ConstraintLayout
...
...
...
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/address_layout"
        android:background="@drawable/rounded_search_bar"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"
        android:orientation="horizontal">
    </LinearLayout>
...
...
...
</android.support.constraint.ConstraintLayout>

The problem now is on the line 现在的问题就在网上

fm.beginTransaction().add(R.id.address_layout, placeAutocompleteFragment, "placeAutocompleteFragment").commit()

I get a type mistake for placeAutocompleteFragment Type mismatch. 我收到placeAutocompleteFragment类型不匹配的类型错误。 Required: Fragment, Found: PlaceAutocompleteFragment? 必需:片段,找到:PlaceAutocompleteFragment?

Any suggestions? 有什么建议么?

Thanks 谢谢

Problem 问题

getChildFragmentManager will return support library version of FragmentManager. getChildFragmentManager将返回FragmentManager的支持库版本。 So you should pass fragment object which inherits support library version of Fragment. 因此,您应该传递继承Fragment支持库版本的fragment对象。

But PlaceAutocompleteFragment inherits android.app.Fragment. 但是PlaceAutocompleteFragment继承了android.app.Fragment。

Solution

Using SupportPlaceAutocompleteFragment instead PlaceAutocompleteFragment. 使用SupportPlaceAutocompleteFragment代替PlaceAutocompleteFragment。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型不匹配。 必需:找到的上下文:在片段中 - Type mismatch. Required: Context Found: In Fragment 类型不匹配。 要求:片段找到:DashboardFragment.Companion - Type mismatch. Required: Fragment Found: DashboardFragment.Companion 类型不匹配。 必需:ContentResolver! 找到:整数 - Type mismatch. Required: ContentResolver! Found: Int 类型不匹配。 要求:观察员<in Int!>成立:? - Type mismatch. Required: Observer<in Int!> Found:? 类型不匹配。 必需:找不到:回调&lt;*&gt; - Type mismatch. Required: Nothing Found: Callback<*> 类型不匹配。 要求:找到的上下文:意图 - Type mismatch. Required: Context Found: Intent 类型不匹配。 必需:结果<newsresponse> : 发现: 结果<response<newsresponse> &gt;? </response<newsresponse></newsresponse> - Type mismatch. Required: Result<NewsResponse>! Found: Result<Response<NewsResponse>>? 类型不匹配。 必需:FirebaseRecyclerAdapter<chatobject, chatvoiceviewholders> ? 成立:</chatobject,> - Type mismatch. Required: FirebaseRecyclerAdapter<ChatObject, ChatVoiceViewHolders>? Found: 类型不匹配。 所需上下文:找到 MyAdapter.ViewHolder - Type mismatch. Required Context: Found MyAdapter.ViewHolder 类型不匹配。 要求:Alignment。水平找到:Alignment - Type mismatch. Required: Alignment.Horizontal Found: Alignment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM