How to create a Toggle Switch in MIT App Inventor
In this tutorial, I will teach you how to create a toggle switch that has more functions than the default one.
The fact that you are here means that you know everything about the MIT App Inventor. If not, click on this link to get started.
let’s dive in.
Goal
You want the switch to perform a different action every time the user taps on it. for instance, turning the flashlight on or off.
Logic
we’ll compare the value of a global variable that we are going to create, and loop through it, That is; if it’s equal to zero then the lights are off and if equal to one the lights are on.
let me “dumb” it down for you.
step 1
Drag and drop a button into the designer view, then go into the blocks view.
create a variable X.
int X = 0
We initialize the variable with a value of zero because we want the lights to be off every time the user opens the app.