Skip to first unread message

SteveJG

unread,
Mar 20, 2019, 9:11:39 AM3/20/19
to MIT App Inventor Forum

Three ways to Filter a simple List

This example demonstrates three ways to Filter a List of data.  It also shows how to make it appear as if three Screens are used. (There is a single screen; vertical arrangements are used to simulate Screens.   )  These methods shown here are suitable for simple Lists and List of csv data.

searchNfilter.jpg

Use Blocks and create a Filtered Sub List
One filtering method uses Blocks to traverse the List.  It creates a sub list and displays the contents of the sub list in a Label and in a scrolling ListView.  Your app probably only needs one of the ways to display the sub list.

ListView with a FilterBar
A second method uses the FilterBar of a ListView. 

ListPicker
 A third method uses a ListPicker.  


The methods are not perfect for all apps.  Each method has advantages and disadvantages.
--------------------------------------------------------------------------------------------------------------------------------------------------
                                     List & subList          ListView                    ListPicker
Filters Automatically            *                   Manual Filtering           Manual Filtering
Case Insensitive                  -                               *                              *

Issues                          case sensitive       keyboard closing             keyboard closing (must select an item)
-----------------------------------------------------------------------------------------------------------------------------------------------------


The example provides a List of 'dates'   shown in the leftmost image above.  The List consists in the following elements  Jan 3|Jan 22|Feb 10|Feb 22|March 1|March 7|March 9|March 22|April 1 (shown as a "csv' using a ! separator)

The example app images above show filtering using the word March or march.  Be aware the List/sub List method is case sensitive, the other two methods ignore case.


The List/sub List method can be used with outside data to populate the 'filter'; the ListView and ListPicker 'filter' key word must be entered manually . 

There are  more elaborate ways of filtering Lists.  One of the best ways to 'filter' is to use an sql database and use sql statements to 'sort' data in your List. How you filter a List depends on the construction of the List or List of Lists and the nonsql database where the List data is stored. If your Lists are complex, you can get around some issues by making a List of csv data and treat it as a simple list.  

Notes

This example by Abraham  might help you see how to build up and scan collections of tags representing multiple tables in a TinyDB ...
https://docs.google.com/document/d/1GLQJY9q3b8KsEAcfzPEcA-j0zWgyRjTI2Pa792znsBI/edit?usp=sharing  A TinyDB is a nonsql database similar to the MIT CloudDB or the FirebaseDB.

ListFilterBlocks.png



Regards,
Steve

filterList.aia
Reply all
Reply to author
Forward
0 new messages