headchef Posted February 23, 2023 Share Posted February 23, 2023 Hi I have posted before about this which you can visit my posts and have a read about again but I have been having issues with customers wanting to order a meal of their head which leads me to pick any item amount but I might be wrong so I will have to go back delete the order and pick all the add-ons again. So I have myself being graduated from computer science degree could not deal with it all everything so I gone ahead and wrote the Android version of the code for you that is because I am using an Android tablet. So please bring this feature onto the Android version of app. Here is the code. // Get the RecyclerView that displays the items val recyclerView = findViewById<RecyclerView>(R.id.items_recyclerview) // Get the adapter used to populate the RecyclerView val adapter = recyclerView.adapter // Create a variable to track the number of selected items var selectedCount = 0 // Set a listener to track changes to the adapter adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onItemRangeChanged(positionStart: Int, itemCount: Int) { // Loop through each item in the adapter for (i in positionStart until positionStart + itemCount) { // Check if the item is selected if (adapter.isSelected(i)) { // Increment the selected count selectedCount++ } else { // Decrement the selected count selectedCount-- } } } }) // Create an extension function to check if an item is selected fun RecyclerView.Adapter<*>.isSelected(position: Int): Boolean { val item = getItem(position) // Check if the item is selected return item.isSelected } Simple as that. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now