Performing single selection from a list
This recipe will display a dialog box, showing a list of items, allowing the user to select one of them. The name of the selected item will be displayed via another dialog box.
How to do it...
In this recipe, we will be making use of the following methods:
dialogCreateAlert()
: This method is used to display a message via the dialog boxdialogSetItems()
: This method is used to define the array of items to be displayed in the listdialogGetResponse()
: This method is used to get a response from the user
Take a look at the following steps:
- First type the following code in the Python script
demoSingleSelection.py
, in the current folder of your computer:
import android app = android.Android() app.dialogCreateAlert("Select your food item") app.dialogSetItems(['Pizza', 'Burger', 'Hot Dog']) app.dialogShow() response = app.dialogGetResponse().result selectedResult=response["item"] if selectedResult==0: app.dialogCreateAlert("You have selected Pizza") elif selectedResult...