RecyclerView всегда 3 элемента с несколькими типами просмотра - PullRequest
0 голосов
/ 01 февраля 2020

У меня есть просмотрщик, который выбирает данные из базы данных Firebase в реальном времени (asyn c). Я хочу завершить счет до 3.

Например; если один элемент извлекается из базы данных, я вставлю этот элемент с тип просмотра A . Затем я вставлю 2 элемента с тип просмотра B . Или, если три элемента выбраны из базы данных, я вставлю их с тип просмотра A . Тогда я не буду вставлять тип представления B

Интересно, как я могу добиться этого?

class InspectedUsersAdapter(val context: Context) : ListAdapter<InspectedUserPOJO,InspectedUsersAdapter.InspectedUserViewHolder>
(object : DiffUtil.ItemCallback<InspectedUserPOJO>(){
override fun areItemsTheSame(oldItem: InspectedUserPOJO, newItem: InspectedUserPOJO): Boolean = oldItem.idStr == newItem.idStr
override fun areContentsTheSame(oldItem: InspectedUserPOJO, newItem: InspectedUserPOJO): Boolean = oldItem.gainedFollower == newItem.gainedFollower}) {


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InspectedUserViewHolder {
    val view = LayoutInflater.from(parent.context).inflate(R.layout.inspected_user_row,parent,false)
    return InspectedUserViewHolder(view)
}


override fun onBindViewHolder(holder: InspectedUserViewHolder, position: Int) {
    val user =getItem(position)
    Glide.with(context).load(user.profileImageUrlHttps?.replace("_normal","")).circleCrop().into(holder.userImage)
    holder.userDisplayname.text = user.name
    holder.userName.text = "@"+user.screenName
    holder.followerCount.text = user.followersCount.toString()
    holder.followingCount.text = user.friendsCount.toString()

    holder.cardview.setOnClickListener {
        var intent = Intent(context,
            InspectedUserActivity::class.java)
        intent.putExtra("USER",user)
        context.startActivity(intent)
    }
}

class InspectedUserViewHolder(view : View) : RecyclerView.ViewHolder(view) {
    val userImage : ImageView = view.findViewById(R.id.inspectedFragment_firstImage)
    val userDisplayname : TextView = view.findViewById(R.id.inspectedFragment_firstName)
    val userName : TextView = view.findViewById(R.id.inspectedFragment_firstUsername)
    val followerCount: TextView = view.findViewById(R.id.inspectedFragment_first_followers_count)
    val followingCount: TextView = view.findViewById(R.id.inspectedFragment_first_following_count)
    val cardview: CardView = view.findViewById(R.id.inspectedFragment_cardview)
}}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...