This post will talk about creating a search bar for your app.
Search Bars are great if you have a lot of text items or List Viewer options that you want to make available to the user without having a lot of items on the Screen at once.
This post will describe how to make a search bar with a search button and a search bar that updates automatically when the text in the search bar changes.
With Search Button
In the Layout for this app, we have:
A Row containing a Text Input and a Button (which is named SearchButton)
A List Viewer
Ignore the Timer in the screenshot, it will be used in the next section
We use two functions in this app.
defineEntireList simply creates a list entireList with the text items that we want the user to search.
updateTempList creates an empty list called tempList, then scrolls through every item in entireList and adds the items which contain the string in the Text Input to tempList.
When every item in entireList has been checked, tempList is now the list of every item from entireList which contains this string.
The items in tempList are then displayed to the user using a List Viewer.
The user can then select an item from this list!
Making a search bar with automatically updating results makes your app look really professional.
The process of assembling and displaying the search results works the same as above. We are simply replacing the trigger.
Instead of updating the search results when the user clicks a Search Button, we will update the results when the text in the Text Input changes.
In the Layout for this app, we have
A Text Input
A List Viewer
A Timer (the shorter the time interval, the faster your results list will update)
We have the same function defineEntireList as earlier.
We have a function suggest, which is executed when the timer fires. If the text in the Text Input has changed since the timer last fired, the updateTempList function is executed. This is basically functioning like a block that says ‘when TextInput1.Text changes, execute updateTempList’.
updateTempList works the same as previously, except that we are searching for the string we named searchString in the suggest function.
You can find a sample app that demonstrates these functions here.