0

i have three model class of username, user and a post just like this

data class User( val uid:String = "" )

data class username( val usernames:String="", )

`data class Post(
        val text:String = "",
        val createdBy: User = User(),
        val createdAt:Long = 0L,
val creates:username = username()

)`

and I have them connected to firebase. Now i want to use both of these models in a single recyclerView adapter. How will i do this? my adapter looks like this

    class postadapter(options: FirestoreRecyclerOptions<Post>, val listener: MainActivity) :
    FirestoreRecyclerAdapter<Post, postadapter.postviewholder>(
    options
    ) {
        class postviewholder(itemview: View):RecyclerView.ViewHolder(itemview) {
            val username: TextView = itemview.findViewById(R.id.userrrrrr)
            val createdat: TextView = itemview.findViewById(R.id.createdAt)
            val Text: TextView = itemview.findViewById(R.id.postedText)
    
        }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): postviewholder {

        val viewholder = postviewholder(LayoutInflater.from(parent.context).inflate(R.layout.feed,parent,false))

        return viewholder
    }
    override fun onBindViewHolder(holder: postviewholder, position: Int ,model: Post) {

        holder.username.text = model.createdBy.uid
        holder.Text.text = model.text
        holder.createdat.text = utils.getTimeAgo(model.createdAt)
    }

}

i also want to pass the value of the username model to the post model of 'creates' also, in the onbindviewholder i want to pass the value of the username i created in the data class.

1 Answers1

0

There is no need for two models, just put everything that is outside, inside. Then use an identifier to access it through the model name.

DATABASE {
   MODEL_ID
        {
          MODEL_ID : 1000
          1000 {
                  EXAMPLE_DATA_ONE: 1001
                  EXAMPLE_DATA_TWO: 1002
OneKe
  • 97
  • 8