Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Creating Alerts in SL4ABack to Android Cookbook Home | Up to Chapter: Other Programming Languages

Author: Rachee Singh ('racheesingh')
In Published Edition? Yes
FormatLanguage: WikiFormat

Creating Alerts in SL4A

Problem

You need to create an alert box or pop-up dialog using Python in the Scripting Layer for Android (SL4A)

Solution

There are many kinds of alert dialogs that can be created using Python in ASE. They can have buttons, lists etc.

Discussion

Choose Python 2.x option from the submenu that appears, like this:

	
  title = 'Sample Alert Dialog'
  text = 'Alert Dialog Type 1!'
  droid.dialogCreateAlert(title, text)
  droid.dialogSetPositiveButtonText('Continue')
  droid.dialogShow()

  title = 'Sample Alert Dialog'
  text = 'Alert Dialog Type 2 with Buttons!'
  droid.dialogCreateAlert(title, text)
  droid.dialogSetPositiveButtonText('Yes')
  droid.dialogSetNegativeButtonText('No')
  droid.dialogSetNeutralButtonText('Cancel')
  droid.dialogShow()

Here is how the alert dialog looks:

Also try this code to create an alert dialog with a list:

  title = 'Sample Alert Dialog'
  droid.dialogCreateAlert(title)
  droid.dialogSetItems(['mango', 'apple', 'strawberry'])
  droid.dialogShow()

Here is how the alert dialog looks:

See Also