var viewHolder: RecyclerView.ViewHolder? = null
when (viewType) {
TYPE_CATEGORY ->{
viewHolder=CategoryViewHolder(LayoutInflater.from(context).inflate(R.layout.item_category_list,parent,false),onItemClickListener)
}
TYPE_SLIDER->{
viewHolder=SliderViewHolder(LayoutInflater.from(context).inflate(R.layout.item_slider_list,parent,false),onItemClickListener)
}
else->{
viewHolder=NewsViewHolder(LayoutInflater.from(context).inflate(R.layout.item_news_list,parent,false),onItemClickListener)
}
}
return viewHolder
}
override fun getItemCount(): Int {
if (data != null) {
return data!!.size
}else{
return 0
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
Log.i("TTTT",getItemViewType(position).toString())
when (getItemViewType(position)) {
TYPE_CATEGORY ->{
(holder as CategoryViewHolder).bindData(data!!.get(position).listData)
}
TYPE_SLIDER->{
(holder as SliderViewHolder).bindData(data!!.get(position).listData)
}
Do'stlaringiz bilan baham: |