Page 310 -
P. 310

two apis


          The SL4A Android API


           The SL4A technology provides a high-level API to the low-level Android API,
           and SL4A’s API is documented in the online API reference:

               http://code.google.com/p/android-scripting/wiki/ApiReference
           Recall the code from earlier, which demonstrated a minimal Android SL4A
           app:
             Import the “android”
             library and create a new
             app object instance.      import android
                                       app = android.Android()
                                       msg = "Hello from Head First Python on Android"
              Create an appropriate
              message and display it on    app.makeToast(msg)
              screen.


           Six calls to the Android API let you create a list of selectable items in a dialog,
           together with positive and negative buttons, which are used to indicate the
           selection your user made. Note how each of the calls to the Android “dialog”
          API results in something appearing on screen.


                    Always start with an import.



                                           Create an Android
          import android
                                           app object.

          app = android.Android()

          app.dialogCreateAlert("Select an athlete:")
          app.dialogSetSingleChoiceItems(['Mikey', 'Sarah', 'James', 'Julie'])
          app.dialogSetPositiveButtonText("Select")
          app.dialogSetNegativeButtonText("Quit")
          app.dialogShow()
          resp = app.dialogGetResponse().result


            Display your dialog      Wait for a response
           on the phone.
                                      from your user.



           274    Chapter 8
   305   306   307   308   309   310   311   312   313   314   315