I am having a hard time to add a different view type to my working recycler view loaded from sqlite database. I want this to be a button in the end of the list since adding a button to the end of the layout is buggy and in the future I pretend to add more view types.
I saw multiple examples with multiple solutions but im a beginner and my java is not very good since im learning android studio with kotlin.
I tried :
Extending recycler view holder
-I could not continue because I didnt understand the java code.
using BaseViewHolder
-I got problems with the return type of the onCreateViewHolder unit and with the declaration of the viewholders, so I could not do it like the examples I found
I think my getItemViewType is working where I add one 1 line with id =-10 after the cursor in the dbhandler to get the different view type in the end of the list.
override fun getItemViewType(position: Int) :Int {
return if (list[position].id.toInt() == -10 ){
VIEW_TYPE_FOLLOWER
}else{
VIEW_TYPE_HEADER
}
}
I have many doubts about the onCreateViewHolder when I try to return ViewHolder and ViewHolder2 I get errors so this is my working viewholder.
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
val v = LayoutInflater.from(p0.context).inflate(R.layout.list_layout, p0 , false)
return ViewHolder(v)
}
view holder
class ViewHolder(itemView: View) :RecyclerView.ViewHolder(itemView){
val textViewName = itemView.findViewById(R.id.textViewName)as TextView
val textViewNameEdit = itemView.findViewById(R.id.textViewNameEdit)as EditText
val textViewAddress = itemView.findViewById(R.id.priorityLevel) as TextView
val notas = itemView.findViewById(R.id.notas) as TextView
}
I want a different view type at the end to make it a button.