Practice and reinforce the concepts from Lesson 7
Time needed: 30-35 minutes
Create an awesome decision-making app called Shaky Picky! When you can't decide what to eat, where to go, or what to do - just shake your phone and let the app pick for you! You'll learn how to use lists to store multiple items and make your app remember them even after closing it.
First, let's see what your app will look like and what components you'll need!
Sample UI | Components You'll Use |
---|---|
![]() |
Layout: • Vertical Arrangement • Horizontal Arrangement Visible Components: • Labels • Image • List Picker ![]() |
After you've saved some items | After you shake your phone |
---|---|
![]() |
![]() |
:bulb: "Good to Know!"
This app needs only 1 screen - so you don't need to create multiple screens!
Now for the fun part - let's make your app work! You'll program what happens when users interact with different parts of your app.
First, you need to create a special variable to store all the items users will add.
What to do:
:bulb: "Stuck?"
You only need 2 blocks for this:
- One block to initialize a global variable
- One block to create an empty list
Now let's program what happens when someone clicks the Save button .
What to do:
Check if the textbox is empty:
The notification that appears when nothing is typed
If the textbox has text in it:
Super important: Make your app smart enough to ignore spaces! If someone accidentally types just spaces, the app should still know the textbox is empty.
:bulb: "Stuck?"
Use the "trim" block to remove spaces from the beginning and end of the text!
Your app should remember what was saved before! Let's make it load the saved items when someone opens the app.
What to do when the app opens:
Here's what your blocks should look like:
These blocks make your app remember previously saved items
:bulb: "Stuck?"
Use the "When Screen1.Initialize" block to run code when the app starts!
Nobody wants to accidentally delete their favorite item! Let's add a confirmation message before deleting anything.
How it works:
What the confirmation looks like:
This message asks users if they really want to delete the item
Make it smart: The message should change based on what item they selected!
:bulb: "Stuck?"
Use the
block to combine:
- The text "Are you sure you want to delete "
- The selected item
- The text "?"
Now let's program what happens when users click "Yes" to delete an item.
What to do after they click "Yes":
:bulb: "Good to Know!"
You don't need to program what happens when they click "No" - the app automatically closes the confirmation box!
This is the coolest part - making your app respond when someone shakes their phone!
What to program:
If the list is empty:
If the list has items:
:bulb: "Stuck?"
- Use the AccelerometerSensor's "Shaking" event
- Use "pick a random item from list" to get a random choice
- Use the TextToSpeech component to make the phone talk!
Ready for an extra challenge? Try making the Advanced Version of Shaky Picky!
Watch this video to see the advanced features in action!
The advanced version looks like this:
Notice the new "Clear All" button at the bottom!
"Clear All" button
No repeats until all items are picked
Smart reset feature
:bulb: "Pro Tip!"
For the advanced version, you might need TWO lists:
- One to store all items permanently
- One to track which items haven't been picked yet
Congratulations on creating your own decision-making app! Test it out by:
Remember to submit your completed app through your course platform!