Hey I am working in Android kotlin. I have respons...
# android
v
Hey I am working in Android kotlin. I have response data, which I want to filter and extract data according. My Response look like this. Inside my response there is three field strengthquantity and subscription. First Block in for strength, second block is for quantity and third block is for subscription. I will explain in more details. For example I want to filter all subscription value who has 25 , 50 and 75 and their value of quantity and subscription are respectfully from the response. Note subscription value is in repoonse is hard code. In real response it will more than 3 categories. I am thinking to use Tree or Graph data structure, but I am not 100% sure. I am doing correct or not. Is there any idiomatic kotlin way to achieved this. I want code to be Performance optimisation, speed, memory etc. I'll send these filter list to RecylerView and will manage to show like below image. Can someone guide me how to filter list through response. Thanks
Screenshot 2022-02-14 at 21.55.35.png
l
I assume you are using a JSON library to deserialize this data into a data class you created. Since
productVariants
is an array, you should use
.filter{data -> quantity.value > value you want it to be greater than}
on your list of data objects. From here you can infer what to do with the other data in your objects.
v
Hey @Landon Patmore yes I am using JSON library to deserialize the data. I am little bit confused on
this value you want it to be greater than
what can I used in here. How can I group then as well?
d
The getter for the array would be fiiltered by the criteria or the server would need to be able to filter based on input to provide you a list based on that criteria.
l
That value would be the value you want your items to be larger then, so as you said in your message, you'd want that to be
25
for example and you'll get every value that is greater then 25, exclusive not inclusive