Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did it this way:</p> <p>1)If is the first click on the widget, then the ImageButton of the widget changes</p> <p>2)If is the second time, then open an Activity and return to the inicial ImageButton state.</p> <p>Im handling click events with setOnClickPendingIntent:</p> <pre><code>private int[] RESOURCES = {R.drawable.button1,R.drawable.button2}; @Override public void onUpdate(Context context, AppWidgetManager mgr, int[] appWidgetIds) { ComponentName me = new ComponentName(context, MyWidgetProvider.class); RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.my_widget); Intent widgetIntent = new Intent(context, MyWidgetProvider.class); Intent myIntent= new Intent(context, MyOtherActivity.class); widgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); PendingIntent pendingIntent; if(clicks == 0) { clicks = 1; remoteViews.setImageViewResource(R.id.my_image_button, RESOURCES[0]); pendingIntent = PendingIntent.getBroadcast(context, 0, widgetIntent, PendingIntent.FLAG_UPDATE_CURRENT); } else if(clicks == 1) { clicks = 2; remoteViews.setImageViewResource(R.id.my_image_button, RESOURCES[1]); pendingIntent = PendingIntent.getActivity(context, 0, myIntent,0); } else //clicks == 2 { clicks = 0; remoteViews.setImageViewResource(R.id.my_image_button, RESOURCES[0]); pendingIntent = PendingIntent.getBroadcast(context, 0, widgetIntent, PendingIntent.FLAG_UPDATE_CURRENT); } remoteViews.setOnClickPendingIntent(R.id.my_image_button, pendingIntent); mgr.updateAppWidget(me, remoteViews); } @Override public void onEnabled(Context context) { clicks = 0; super.onEnabled(context); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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