• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any idea about my prblem please
 
Rancher
Posts: 665
10
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean if the the row of recyclerView is clicked, it will change to another color?
 
reply
    Bookmark Topic Watch Topic
  • New Topic