Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Cargar recicladorver diferentes tipos de adaptador con encabezado de mes

Intentando mostrar el nombre del mes como encabezado si obtiene un nombre de mes diferente de api. Aquí cargo el encabezado del mes, pero cuando cargo el encabezado no carga otra vista. Necesito que cargue el mes como encabezado si es diferente en datos y también cargue otro titular de vista.

Vi algunos ejemplos en los que todos usan groupItem dentro de la clase Model. No puedo cambiar la clase de modelo ahora. Si puede resolver esto sin él.

ReportsAdapter.kt

 class ReportsAdapter( private val onClickListener: (TimelineVisit) -> Unit ) : ListAdapter<TimelineVisit, RecyclerView.ViewHolder>( DiffUtil() ) { private var month: String = "" inner class ReportsViewHolder(private val binding: ItemVisitBinding) : RecyclerView.ViewHolder( binding.root ) { fun bind(item: TimelineVisit, onClickListener: (TimelineVisit) -> Unit) { binding.apply { linearLayoutPaymentStatus.visibility = View.GONE imgFeedback.visibility = View.GONE var text = item.visitFrom root.setOnClickListener { onClickListener.invoke(item) } } } } inner class MonthHeaderViewHolder(val binding: ItemMonthNameBinding, val bindingVisit: ItemVisitBinding) : RecyclerView.ViewHolder( binding.root ) { fun bind(month: String, item: TimelineVisit, onClickListener: (TimelineVisit) -> Unit) { bindingVisit.txtMonthName.text = month binding.apply { linearLayoutPaymentStatus.visibility = View.GONE imgFeedback.visibility = View.GONE var text = item.visitFrom root.setOnClickListener { onClickListener.invoke(item) } } } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return when (viewType) { R.layout.asm_item_month_name -> { val monthView = ItemMonthNameBinding.inflate(LayoutInflater.from(parent.context), parent, false) val mView = ItemVisitBinding.inflate(LayoutInflater.from(parent.context), parent, false) MonthHeaderViewHolder(monthView, mView) } R.layout.asm_item_visit -> { val mView = ItemVisitBinding.inflate(LayoutInflater.from(parent.context), parent, false) ReportsViewHolder(mView) } else -> { val mView = ItemVisitBinding.inflate(LayoutInflater.from(parent.context), parent, false) ReportsViewHolder(mView) } } } override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { when (holder) { is ReportsAdapter.MonthHeaderViewHolder -> holder.bind(month, getItem(position), onClickListener ) is ReportsAdapter.ReportsViewHolder -> holder.bind(getItem(position), onClickListener) } } override fun getItemViewType(position: Int): Int { //if month get different month will load monthHeaderViewHolder val currentMonth = getItem(position).visitFrom return if (month != convertCurrentMonth) { month = convertCurrentMonth R.layout.item_month_name } else { R.layout.item_visit } } } class DiffUtil : DiffUtil.ItemCallback<TimelineVisit>() { override fun areItemsTheSame(oldItem: TimelineVisit, newItem: TimelineVisit): Boolean { return oldItem.profileId == newItem.profileId } override fun areContentsTheSame(oldItem: TimelineVisit, newItem: TimelineVisit): Boolean { return oldItem == newItem } }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!