I’m a little confused with Android app widgets. I understand that I can create a button to start an activity, but I don’t see how I can create a button to edit the text of a TextView inside the widget.
Can someone please tell me what I’m missing?
Thanks a lot in advance.
EDIT:
I don’t mean for the user to input the new text, I mean for the application to change the text automatically, without any UI (i.e., dialog boxes or activities).
EDIT:
OK, so you set a getBroadcast PendingIntent on your button with setOnClickPendingIntent and perform your update (or call your update method) with the new text from the receiver. Your AppWidgetProvider class can be your receiver (you can catch your intent in onReceive), otherwise you create a new class that extends BroadcastReceiver.
EDIT2 (sample code):
I didn’t run/compile this code so hopefully it will not have errors.
This is a simple helper method to get a basic update pending intent with a custom action:
Catch the custom action in onReceive in your overridden AppWidgetProvider class
You will also need to add an IntentFilter for the custom action to your manifest in the appwidget receiver declaration
Finally you apply the pending intent to your RemoteViews where ever you are building it so when the button is clicked it will send the my.package.ACTION_UPDATE_WIDGET action, which will be caught by your AppWidgetProvider, where you can (or call a method to) perform your AppWidget update