How To Get The Total Count In Cart Using Recyclerview Adapter
Hi I am using Recyclerview with Adapter in my Android application. In my app I have product listing screen, where user can set the quantity in every list item. I am using two image
Solution 1:
use cartlist.size()
for total count.
and for using in activity define this in Adapter class:
classProductAdapter(privateval..
{
...
fungetCartSize():Int {
return cartlist.size()
}
...
}
and in the activity you can use :
adapter.getCartsize()
Solution 2:
since you are just passing the list into the recycleview
and want to use it in fragment or activity. I would suggest using the list to get the total count for your items instead. You can use sumOf
to your list.
you can use it like this before you pass to recyclver view.
valtotalCount= list.sumOf { it.quantity }
or
txtView.text = list.sumOf {it.quantity}.toString()
Post a Comment for "How To Get The Total Count In Cart Using Recyclerview Adapter"