class CustomeAdapterForTopics(
val ctx: Context,
var clickListener: OnTopicClick,
val items: ArrayList<ModelForTopics>
) : RecyclerView.Adapter<TopicViewHolder>() {
override fun onBindViewHolder(holder: TopicViewHolder, position: Int) {
val user: ModelForTopics = items[position]
holder.textViewName.text = user.name
holder.initilise(items.get(position), clickListener)
// if() {
// holder.textViewName.setTextColor(Color.parseColor("#FFA07A"));
//
//
// } else {
// holder.textViewName.setTextColor(Color.parseColor("#FFBA5F"));
//
// }
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TopicViewHolder {
val v = LayoutInflater.from(parent?.context).inflate(R.layout.topics_row, parent, false)
return TopicViewHolder(v)
}
override fun getItemCount(): Int {
return items.size
}
}
class TopicViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
// var itemViewList: List<View> = ArrayList()
val textViewName = itemView.findViewById(R.id.textView) as TextView
// itemViewList.add(itemView);
fun initilise(items: ModelForTopics, action: OnTopicClick) {
textViewName.text = items.name
// textViewName.setTextColor(Color.parseColor("#25375F"))
itemView.setOnClickListener {
action.onItemClick(items, adapterPosition)
// textViewName.setTextColor(Color.parseColor("#FFBA5F"))
// if() {
// textViewName.setTextColor(Color.parseColor("#FFBA5F"))
// }
// else{
// textViewName.setTextColor(Color.parseColor("#25375F"))
// }
}
}
}
interface OnTopicClick {
fun onItemClick(items: ModelForTopics, position: Int)
}
I want to change the color for selected item which is shown through recyclerView. I just don't get the position of selected item. I just saw the solution on internet but didn't get it, or they are mostly of java code. Im new on development. Just let me find the exact position of clicked item so i can put condition in if else function