0

I would like to show only 1st position item and hide other same text items in recyclerView. just like image below.

enter image description here

I know I can hide the view with holder.itemView.visibility = View.GONE, but what condition should I implement to achieve this? Thank you.

Tieria
  • 333
  • 3
  • 11

3 Answers3

2

I have a counter idea. I feel the list should be filtered for uniqueness before displaying in the recyclerview.

Having something like:

data class Fruits(val name: String, val timeStamp :String)
val fruits = listOf(
    Fruits("Apples", "Foo"),
    Fruits("Apples", "Bar"),
    Fruits("Oranges", "Foo"),
    Fruits("Apples", "Bar")
)   

then using:

fruits.distinctBy{
    it.name
}

should remove duplicate items with the same name and this is what you pass to the adapter

Robin
  • 904
  • 8
  • 16
0

I could resolve this problem with How do I display the calendar date on the top of chat messages?

Get previous position with

if(position > 0) {
            val previousPosition = cellList[position -1]
        }

and compare with current position. Thanks for you guys' help!

Tieria
  • 333
  • 3
  • 11
0

I want to complete answer of my friend Robin if u want to hold the first item, you should also sort them

fruits.sortedByDescending { it.date }.distinctBy { it.name }