• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Kotlin : How to change the background color of selected item in recyclerview

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a kotlin mobile app. In my app i use the recyclervie with adapter.
I want to changing the color of item clicked  in my recyclervview, and when i clik on another item, the color will be change and the color of the first item clicked return to the default color.
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
       val itemCategory: ProductCategoryData = categories[position]
       holder.categoryId.text = itemCategory.id.toString()

       println(holder.categoryId.text)
       println(itemCategory.name?.get("En").toString())
       holder.categoryName.text = itemCategory.name?.get("En").toString()
      ............
       holder.itemView.setOnClickListener {
           rowindex = position
           mListener?.onItemClick(holder.itemView, categories[position])
       }
       if (rowindex == position) {
           holder.itemView.setBackgroundColor(Color.parseColor("#FED07A"))
       } else {
           holder.itemView.setBackgroundColor(Color.parseColor("#ffffff"))
       }

   }
 
Maha Sakka
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea about my prblem please
 
Ranch Foreman
Posts: 323
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean if the the row of recyclerView is clicked, it will change to another color?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!