I have a widget (AppWidgetProvider) and I want to know if there is a way to support multiple clicks. Example:
1) If the first click on the widgets, the ImageButton of the widget changes (for example, changes color).
2) If this is the second time, then open Activity.
- Is there any way to handle click events inside AppWidgetProvider?
My code is:
public class MyWidgetProvider extends AppWidgetProvider
{
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.control_widget);
views.setOnClickPendingIntent(R.id.asdf, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
My widget works great. When I click ImageButton (R.id.asdf), it goes to MyActivity.
I like to know how I can handle click events on my widget in order to take another action (for example: change the color of the ImageButton), and not go to any activity. Is there any other way for any click handle other than setOnClickPendingIntent ()?
source
share