Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

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: 582
9
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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic