Displaying Data in the ListView
The next step in the making of your app is creating a way to see all the accessbile places. You want to program it so that it finds all the place entries and then adds each one as an element of the ListView in the ListOfPlaces screen. To do this, you are to need the FirebaseDB component again.
-
Switch to the ListOfPlaces screen and drag out a FirebaseDB component onto the Designer view.
-
Now switch over to the Blocks view, and take out a
when ListOfPlaces.Initialize
block. Everything in this will run as soon as this screen opens up. -
Place a
call FireBase.GetTagList
block inside this block. This tells Firebase to return a list containing the tags of all saved data in your database.
- Take out a
when FireBase.TagList
block and insert afor each item in list
block inside it. This function will run as soon as Firebase gets our collection of tags in the form of a list, which it uses as thevalue
variable.
With the for
loop you now have individual tags being set to the item variable. Of course you don’t want the tag, you want the address, and you’ll use the tag to get it.
Grab a call Firebase.GetValue
block, and set the tag to the item
variable, since this contains the current tag from the value
list.
-
Add a
when Firebase.GotValue
block, and put aadd items to list
block inside it. -
You will need a list to add locations to, so add an
initialize global name
block. Change itsname
tolocations
and drag acreate empty list
block onto the end of it. -
Now attach a
get global locations
block to the list attachment of theadd items to list
block, and aget value
block to the item attachment. Thevalue
variable contains the address of the place.
Note: the list of tags will also contain the "PlaceNumber"
tag that you’re using to keep count of the places, so you’ll need to exclude that from the list you display.
-
Add an
if then
block from Control to yourGotValue
block, and move theadd items to list
code so it’s inside thethen
block. -
Onto the
if
part: attach anot
and an=
from Logic. Hover over thetag
variable and put aget tag
on the left of the=
. tThen put a""
Text block on the right and type"PlaceNumber"
into it.
- Lastly you need to tell the ListView to get its elements from your list. Get a
set ListView.Elements
block and attach aget global locations
block to it.