class AllCategoryAdapter(val categoryList : List<AllCategoryBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>()
{
private val TYPE_HEADER : Int = 0
private val TYPE_LIST : Int = 1
override fun getItemViewType(position: Int): Int {
if(position == 0)
{
return TYPE_HEADER
}
return TYPE_LIST
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
if(viewType == TYPE_HEADER)
{
val header = LayoutInflater.from(parent.context).inflate(R.layout.cv_all_category_header,parent,false)
return ViewHolderHeader(header)
}
val header = LayoutInflater.from(parent.context).inflate(R.layout.cv_all_category,parent,false)
return ViewHolder(header)
}
override fun getItemCount(): Int {
return categoryList.size + 1
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val listItem : AllCategoryBean = categoryList[position]
if(holder is ViewHolderHeader)
{
holder.tvCategoyName.setText("All Category")
}
if(holder is ViewHolder)
{
holder.tvCategoyName.setText(listItem.getCategoryName())
}
}
class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView)
{
val tvCategoyName = itemView.findViewById(R.id.tvCategoyName) as TextView
}
class ViewHolderHeader(itemView : View) : RecyclerView.ViewHolder(itemView)
{
val tvCategoyName = itemView.findViewById(R.id.tvCategoyName) as TextView
}
}