• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

kotlin/jetpack search list

ka0ttic

Lurker
I am looking for some advice on an app I have been developing over the last couple months. In an abstract explanation, the app's main screen (MainScreen()) shows items that the user has added. There is an add button which loads an add screen (AddScreen()) which by default shows all possible items that can be added. I have a search text field with a filter list underneath and have implemented some logic that has them work together to only show items that match both the search and filter criteria.

Currently, I am using just a regular mutable list to hold items that should be displayed. If there's nothing in the search text field and no filters are selected than we just assign the entire list (defined in a view model) to the regular mutable list in AddScreen()

Code:
val resultsList = mutableListOf<whatever>()
...
if (dontFilter && dontSearch)
    resultsList = viewmodel.itemMap.values.toMutableList()
else {
    // do search/filter logic
    resultsList.add(whateverItem)
}
LazyColumn(items = resultsList) {
...
}

the variables that are associated with the search text field (onValueChange) and filters (onClick) are all state variables but should the resultsList be a state variable defined in the view model as well?

I have a random bug that I am trying to find but cannot seem to reproduce when I try. It may have something to do with process death but after I have added an item from AddScreen and then click add to load AddScreen again, the list sometimes does not show all possible items (all of ItemMap.values in above example), even though the search text field and filters have been cleared.

I need to pay more attention to whether this happens after I am using an already running an instance of the app (and process death may have occurred) or if it is a new instance... I am thinking the former though because it always seems to happen when I am quickly trying to show someone else the app (naturally...) as opposed to me restarting an app while testing after a code change.

Any advice?
 
Back
Top Bottom