Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid widget button custom dialog
    text
    copied!<p>Is it possible to open a custom dialog from widget button? I created a widget with a button. With <a href="http://www.helloandroid.com/files/xmaswidget/android_howto-hellowidget.pdf" rel="nofollow">this</a> tutorial if i click ButtonP1 a toast msg appears. But i want a custom dialog to appear. There is also an intent example for the button in the tutorial but for my custom dialog it is not working, however if i want to open an activity with that it is working fine. I want a custom dialog to appear when user clicks on a button on the widget.</p> <p>Here is this code where Main.class is an activity:</p> <pre><code>public class HelloWidget extends AppWidgetProvider { public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget"; public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { context.startService(new Intent(context, UpdateService.class)); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetmain); Intent configIntent = new Intent(context, Main.class); configIntent.setAction(ACTION_WIDGET_CONFIGURE); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.ButtonP1, configPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); } </code></pre> <p>When i change Main.class to CustomizeDialog.class, nothing happens.</p> <p>The CustomizeDialog.java looks like this in a nutshell:</p> <pre><code>public class CustomizeDialog extends Dialog implements OnClickListener { Activity mActivity; public CustomizeDialog(Activity activity) { super(activity); mActivity = activity; ... } @Override public void onClick(View v) { if (v == okButton) { dismiss(); } if (v == cancelButton) { dismiss(); } } } </code></pre> <p><strong>Edit 06.21.2011</strong></p> <p>Thank to you guys, i was able to call an activity with framelayout which is almost what i wanted. However, I want to do this with a customdialog, but with the code i am using, it is not appearing when i click on the widget button:</p> <pre><code>Intent configIntent = new Intent(context, CustomizeDialog.class); configIntent.setAction(ACTION_WIDGET_CONFIGURE); PendingIntent configPendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_THREE, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.ButtonP3, configPendingIntent); </code></pre> <p>If i change CustomizeDialog.class to Main.class, which is an activity, it is working fine.</p> <p>Please find CustomDialog.class's structure above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload