• 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: Get clicked item in recyclerview adapter

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create an android app with Kotlin. In this app, i use swagger also to get all the web service in a file.
I want to create an interface,the description is as follows :
A recycler view horizontal that contains all the list of categories comes from a web service "apiMobileProductCategoriesGetAllPost".
after that, when i click on a which category, a recyclerview(Grid) appear that contains all the product by category id.
I want to know how can i get the categry id when i click on item,and how to use it in the activity
The following the recyclerview category adapter :



The following code is relative to the activity:

 
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you get so far in this line?

println(itemCategory.id)
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The id of all the category existing, my goal is when i click on category item i get all the product with categoryid
 
Randy Tong
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside onBindViewHolder of your adapter class, you can do something like this
In activity class
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why when i click on the item the click action does not apply.
 
Randy Tong
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pass your class listener to adapter class
In adapter class
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still have the same problem
 
Randy Tong
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post your latest code
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's my new code, i don't know why the "onItemClick" in the activity didn't work
i'm very stuck, could you please help me

the following the adapter :


the following the activity :

 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help please, i lost a lot of time
 
Randy Tong
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you are not using my suggestion code.
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get an error when i use your code that's why i change another thing

error : Unresolved reference: OnItemClickListener
My goal is to make my code functional, should you please help me
 
Randy Tong
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Randy Tong wrote:Pass your class listener to adapter class
In adapter class


Did you pass class listener to adapter class?
 
Randy Tong
Ranch Foreman
Posts: 313
4
Android Tomcat Server Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Maha Sakka wrote:I get an error when i use your code that's why i change another thing

error : Unresolved reference: OnItemClickListener
My goal is to make my code functional, should you please help me


My bad ! This is the correct one
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i will try again and i will tell the result later
 
Maha Sakka
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, that's great the onClickItem()it work very well thank you

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!