Reputation: 26971
I have an activity that retrieves a list of items that i want to show inside of a widget. Since ListViews are not supported inside widgets before Android OS 3.0, I would like to get other opinions on how to implement this.
Maybe some of you have created such a widget?
I want to load each item into the widget, into a TextView and display a next arrow. When the next arrow is clicked the next item will be displayed without the activity running and retrieving it all over again.
If anyone could please provide further information on how to go about doing this, or maybe a better way
Thanks
Upvotes: 0
Views: 248
Reputation: 915
First, if you haven't already, I recommend reading through http://developer.android.com/guide/topics/appwidgets/index.html#AppWidgetProvider. You can set up your AppWidget's layout to include a TextView, and a next button/image. Remember to give them ids so that you can set an setOnClickPendingIntent. The basic foundation of an AppWidgetProvider is that of a BroadcastReceiver, so you can create an intent with a custom Intent (i.e. MyAppWidgetProvider.ACTION_NEXT) that will advance your cursor or index for your list or array to the next item, and within onUpdate, render the RemoteView to that you want to have display your data.
I'm unclear in what you mean by that you have an activity that retrieves a list of items, but if you want to send a list of things to an AppWidget to display, you can do so from your Activity by creating an Intent specific to your AppWidgetProvider with the list as an extra that the onReceive in the AppWidgetProvider will receive. The AppWidgetProvider is a subclass of BroadcastReceiver, hence you have onReceive. Or if you want to obtain that list from the activity, make it available to get from the activity through the AppWidgetProvider's onUpdate or onEnabled.
Either way, you can store the data to a global object, and do what you want with it whenever onUpdate is triggered or if something else broadcasts to your AppWidget.
If you poke around the web, you'll find some more examples of this. Google's StackView example, although it's using the StackView (which is only available post 3.0) is a good example of how you can use onReceive and actions to direct how your widget and data work.
Upvotes: 2