I’m developing an android widget. In the widget I have a text field and two buttons. When I press button1 I want the text field to show a certain text, like “one,” and if I click button2, the text field will show like “2.”
the onUpdate() looks like this :
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){ super.onUpdate(context, appWidgetManager, appWidgetIds);
remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main);
Intent intent = new Intent(context, CalculatorReceiver.class);
intent.setAction(ACTION_WIDGET_RECEIVER);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.one, actionPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); }
and the onReceive() method looks like this:
@Override public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if(intent.getAction().equals(ACTION_WIDGET_RECEIVER)){
Toast.makeText(context, "Hi I'm 1", Toast.LENGTH_LONG).show();
}}
Now, in the widget, I’m only able to show a Toast when a button pressed, but I want to get the textView and change its value. How do I get and change the textView?
You can't get the values of views from your widget.
You can update TextView
of the widget by using RemoteViews
remoteViews.setTextViewText(R.id.text_view_id, "Your text");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With