The ListView
implements methods for filtering the content. Can you elaborate on when it should be used?
As I understand it, that kind of filtering is suitable for the array based adapter -- all data already is in memory. This way, the filter just helps to skip the data that should not be displayed.
However, if the ListView
is used with a cursor adapter (SQLite database) for displayig a lot of items, the data may not be in memory. On the other hand, the filter value can be embed in the SQL query to get the reduced data set effectively.
Was the filtering mechanism for ListView
designed also for the cursor based data? When the Filterable
should be used and when filter should be passed to the SQL query without using ListView filters? Are there any recommendations when this or that approach should be used?
Thanks
P.S. The question was separated from How the system of URIs should be designed? that combined the two earlier.
Was the filtering mechanism for ListView designed also for the cursor based data?
The filtering mechanism through the Filter
class was implemented for the adapter(a logical action to do with an adapter), the ListView
is just a simple user of that adapter.
When the Filterable should be used and when filter should be passed to the SQL query without using ListView filters? Are there any recommendations when this or that approach should be used?
I don't think there are any recommendation on which one to use(or I didn't see them myself). The Filter
class however is specially designed to optimize the filtering process(for example if the initial filtering operation takes some time and the user makes other requests in this time, then the Filter
class will only perform the last filtering operation scheduled(the other wouldn't make sense to do)). To my shame, I don't know if the CursorLoader
will cancel a load if the onLoaderReset()
callback is called in that time, if it doesn't do this it would be bad because you'll do all of them(if the user makes the filtering after abcd fast, you wouldn't want to do a b c d, you'd want to do a d). You could optimize that but the hassle vs a filter wouldn't make sense.
However, if the ListView is used with a cursor adapter (SQLite database) for displayig a lot of items, the data may not be in memory. On the other hand, the filter value can be embed in the SQL query to get the reduced data set effectively.
Measure stuff. Making new queries with a bigger constraint will reduce the data set at the cost of the user seeing the result slower. If the time is unacceptable maybe it would make better sense to make a single query(for the initial constraint) and then filter that data set without additional sqlite queries.