14. UI Response

Before we get too much further it’s important to test that our app is actually working. What we’re going to do is get the buttons to pop up a quick message just so we know they’re working. Copy the following code into your click methods:

Toast.makeText(getApplicationContext(),
               "Hit button clicked",
               Toast.LENGTH_SHORT).show();

A Toast is the Android way to have a message pop up on the screen. You can put it all on one line if you like but it wouldn’t fit on one line for this tutorial so I’ve split it up. You’ll also have to reset the imports by pressing Ctrl-Shift-O again but now when you test your app the buttons should respond, i.e:

This is what the app looks like on my Galaxy Nexus phone which is running Android 4.1. It has a much higher resolution than other Android phones so whatever you’re testing on could look vastly different. As long as your screen contains everything and the little message pops up when you click on your buttons. You’re ready to proceed.

If you’re having problems then it’s best you completely sort them out right now. Trying to forge on while you’ve got errors is futile, particularly since we’re now going to have to incorporate some slightly tricky code. If you have any problems that revision of the previous lessons can’t fix, then feel free to ask for help below.

One thought on “14. UI Response

  1. Hi i keep getting error on
    PID: 27291
    java.lang.StackOverflowError
    can’t seem to run my app at all. it keeps shutting down.

    at com.example.michaelmichael.blackjtrainer.MainActivity

Leave a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>