简体   繁体   English

Firestore Recycler 适配器 - 多种视图类型

[英]Firestore Recycler adapter - multiple view types

I want to create a chat activity that will use data from Firestore database and display messages in two different layouts.我想创建一个聊天活动,它将使用 Firestore 数据库中的数据并以两种不同的布局显示消息。

For that I'm gonna need an adapter with multiple view types.为此,我需要一个具有多种视图类型的adapter Tried using a single view type and hiding TextViews and it resulted in display problems in the app.尝试使用单一视图类型并隐藏TextViews ,结果导致应用出现显示问题。

I found solutions to create such an adapter for either Firebase Realtime Database or javascript, but I can't find any for Firestore Database and Java using Android Studio. I found solutions to create such an adapter for either Firebase Realtime Database or javascript, but I can't find any for Firestore Database and Java using Android Studio. How should I proceed?我应该如何进行?

swapAdapter ? swapAdapter

Basically set a simple a simple firestore and all the required instances like RecyclerView , Model , ViewHolder , adapter1 , adapter2 , etc...基本上设置一个简单的firestore和所有必需的实例,如RecyclerViewModelViewHolderadapter1adapter2 etc...

this is a very good example: How to display data from Firestore in a RecyclerView with Android?这是一个很好的例子: How to display data from Firestore in a RecyclerView with Android?

and then use swapAdapter to swap the current adapter with the provided one.然后使用swapAdapter将当前适配器与提供的适配器交换。 It is similar to setAdapter(Adapter) but assumes existing adapter and the new adapter uses the same ViewHolder and does not clear the RecycledViewPool .它类似于setAdapter(Adapter)但假定现有适配器和新适配器使用相同的ViewHolder并且不清除RecycledViewPool

docs: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#swapadapter文档: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#swapadapter

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM