Appinventor Programming

Today we will see with two appinventor apps, which will give us a chance to work with:

"Did you Exercise?" App

In this app, the user is presented with a question:

"Did you exercise today?":

and a list of possible answers ("YES, and "NO"):

The user can presumably answer this question every day, over a period of time. When the user decides to get the results from this activity, she will see something like this:

This app is already programmed for you. Here is the appinventor code for this app:

Initializations code above:

and the rest of the code (event handlers):

Discussion points on the code above

Notice the definition of the variable choicesList, which holds a list of two elements, each being a piece of text.

The choicesList is used to initialize the ChoicesPicker, as soon as the screen opens (on the "Initialize" event of Screen1 component).

The variables numYES and numNO will eventually hold the number of the positive and negative answers, respectively.

The variable currentAnswer will hold the answer of the user every time she answers the question. Notice how this variable gets its new value right after the user has picked an answer ("AfterPicking" event handler, in the "ChoicesPicker" component.) Next, the program is using an ifelse statement to act based on what the user's current answer was: if it was "YES", then the counter for the positive answers is incremented by one. In the opposite case, the counter for the negative answers is incremented.

When the ResultsButton is clicked, the ResultsButton.Click events handler is executed. At that time, the total number of answers (numYES + numNO) is computed, and displayed, together with the number of positive and negative answers.

"Time Spent OnLine" App

In this task we will create anappinventor app that will track the time the user is spending online on a daily basis. After some days of recording, the user can get the total number of hours she has spend online over that period. In addition, she will see the time spend on line from the first day of recording to the present.

Create the interface

We will create a basic interface for this app:

Program the app

In this case, we will need to maintain the user's choices over several days. For this we will use a List. Open the BlocksEditor.

Initializations

ChoicesPicker.AfterPicking event handler

ResultsButton.Click event handler