1

I would like to make a popup window with a textview from my widget (AppWidgetProvider), I want 2 buttons in the bottom "Update" and "Close". I tried using a AlertDialog but it crashes the widget.

AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage("Sample text")
                   .setCancelable(false)
                   .setPositiveButton("Update", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           CallUpdate(context);
                       }
                   })
                   .setNegativeButton("Close", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                       }
                   });
            builder.show();

I want to be able to use Spanned text.

Thanks.

BlackVoid
  • 627
  • 1
  • 6
  • 21
  • How does it crash? I don't see anything obviously wrong with what you have there but of course we can't run it ourselves... – Rob I Apr 27 '12 at 13:08

2 Answers2

2

You cannot display an AlertDialog from an AppWidgetProvider. You will need to create an Activity and use that instead, via startActivity(). You can theme the activity to look like a dialog if you so choose.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
2

an App Widget can support the following layout classes:

FrameLayout
LinearLayout
RelativeLayout

And the following widget classes:

AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

so you can not show AlertDialog from AppWidgetProvider. You can start an actvity on button click which look like a alertDialog.

FOR LAUNCHING an activity on Home Screen Widget click you can see these posts:

Launching activity from widget

How to launch activity from android home screen widget

Community
  • 1
  • 1
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213