1

I want to create a chat activity that will use data from Firestore database and display messages in two different layouts.

For that I'm gonna need an adapter with multiple view types. Tried using a single view type and hiding TextViews and it resulted in display problems in the app.

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?

0xA
  • 1,519
  • 1
  • 9
  • 23
Xarxes
  • 89
  • 1
  • 8
  • 1
    The key to solving this issue is to use [two different layouts](https://github.com/alexmamo/Firestore-ChatApp/blob/74ffafa07c7b4faca30ce94f113eb51802068769/app/src/main/java/ro/alexmamo/chatapp/activities/ChatActivity.kt#L98). Here you can find a tutorial on how to create a complete and functional [Firestore Chat App](https://www.youtube.com/playlist?list=PLn2n4GESV0Ak1HiH0tTPTJXsOEy-5v9qb). – Alex Mamo May 27 '20 at 08:01
  • Is there a way to convert such Kotlin code/project to Java? My whole project is in Java. – Xarxes May 27 '20 at 12:44

1 Answers1

1

swapAdapter?

Basically set a simple a simple firestore and all the required instances like RecyclerView , Model , ViewHolder , adapter1 , adapter2 , etc...

this is a very good example: How to display data from Firestore in a RecyclerView with Android?

and then use swapAdapter to swap the current adapter with the provided one. It is similar to setAdapter(Adapter) but assumes existing adapter and the new adapter uses the same ViewHolder and does not clear the RecycledViewPool.

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

0xA
  • 1,519
  • 1
  • 9
  • 23