I developed a widget for Android with the intention of clicking a text widget's icon is changed. To do this I set the action and I have tried the method OnReceive action. This is the code:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_WIDGET_NOTIF)) {
Bundle extras = intent.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
RemoteViews controles = new RemoteViews(context.getPackageName(),
R.layout.widgetcuatroxuno);
controles.setImageViewResource(R.id.btt,
R.drawable.ic_launcher_new);
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, controles);
} else {
super.onReceive(context, intent);
}
}
I know I need AppWidgetManager to update the widget controls, but it failed. How I can fulfill my purpose? Sorry for my English. Thank you very much for everything.
RemoteViews control = new RemoteViews(context.getPackageName(),
R.layout.widget);
control.setTextViewText(R.id.textview1, "ExampleText");
ComponentName cn = new ComponentName(context,
ButtonWidget.class);
AppWidgetManager.getInstance(context).updateAppWidget(cn,
control);
This one works in OnReceive(), thanks a lot!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.