Guruh: 314-17 Bajardi: Ne’matjonov A


Download 1.68 Mb.
bet22/22
Sana08.01.2022
Hajmi1.68 Mb.
#247739
1   ...   14   15   16   17   18   19   20   21   22
Bog'liq
Ne'matjonov Abduvohid

else->{

(holder as NewsViewHolder).bindData(data!!.get(position).listData)


}


}

}

override fun getItemViewType(position: Int): Int {




return data!![position].listData.type

}

interface OnItemClickListener{




fun onItemClick(view: View,data:Any)

}

class NewsItemAdapter(



var data: ArrayList,

var onItemClickListener: HomeAdapter.OnItemClickListener?

) :


RecyclerView.Adapter() {

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



var holder = NewsItemViewHolder(

LayoutInflater.from(parent.context).inflate(

R.layout.item_news,

parent,


false

)

)



return holder

}

override fun getItemCount(): Int = data.size



override fun onBindViewHolder(holder: NewsItemViewHolder, position: Int) {

holder.setData(data[position] as NewsData)

holder.itemView.setOnClickListener {

onItemClickListener?.onItemClick(holder.itemView,data[position] as NewsData)

}

}

class NewsItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {



var image: ImageView

var title: TextView

var description: TextView

var type: TextView

init {


image = itemView.image_news_item

title = itemView.title_news_item

description = itemView.description_news_item

type = itemView.type_news_item

}

fun setData(data: NewsData) {

image.setImageResource(data.image)

title.text = data.title

description.text = data.description

type.text = data.type

}

}



class SliderItemAdapter(

var data: ArrayList,

var onItemClickListener: HomeAdapter.OnItemClickListener?

):RecyclerView.Adapter() {

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

var holder=SliderItemViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_slider,parent,false))

return holder

}

override fun getItemCount(): Int=data.size



override fun onBindViewHolder(holder: SliderItemViewHolder, position: Int) {

holder.setData(data[position] as SliderData)

holder.itemView.setOnClickListener {

onItemClickListener?.onItemClick(holder.itemView,data[position] as SliderData)

}

}

class SliderItemViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {



var image:ImageView

var title: TextView

var description: TextView

init {


image = itemView.image_slider_item

title=itemView.title_slider_item

description=itemView.description_slider_item

}

fun setData(data: SliderData) {

image.setImageResource(data.image)

title.text = data.title

description.text = data.description

}

}



}

Download 1.68 Mb.

Do'stlaringiz bilan baham:
1   ...   14   15   16   17   18   19   20   21   22




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling