I am building a widget that has several pages of information. Only one page will be displayed at a time, and when a user taps on the widget, the next page will be displayed. I would like to create this functionality by using a ViewFlipper, however I can not find any documentation on how to implement it for a widget.
Here is skeleton code I am using while trying to get the ViewFlipper to work.
I have widget (DivisionStandings ) that has the content inserted into the layout (mainLayout) with a service (UpdateService).
When running the widget, I initially see the text for header1 set to "Updated Header" as intended. Touching the widget however does nothing.
[BroadcastReceiver (Label = "aaWdiget")]
[IntentFilter (new string [] { "android.appwidget.action.APPWIDGET_UPDATE" })]
[MetaData ("android.appwidget.provider", Resource = "@xml/divisionstandings")]
public class DivisionStandings : AppWidgetProvider
{
public override void OnUpdate (Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
context.StartService (new Intent (context, typeof (UpdateService)));
}
}
[Service]
public class UpdateService : Service
{
public override void OnStart (Intent intent, int startId)
{
RemoteViews mainView= new RemoteViews (this.PackageName, Resource.Layout.mainLayout);;
ComponentName thisWidget = new ComponentName (this, "mlbstandings.DivisionStandings");
AppWidgetManager manager = AppWidgetManager.GetInstance (this);
mainView.SetTextViewText(Resource.Id.header1, "Updated Header");
ViewFlipper flipper = (ViewFlipper)Resource.Id.viewFlipper1;
flipper.Touch += (object sender, View.TouchEventArgs e) => {
flipper.ShowNext();
};
manager.UpdateAppWidget (thisWidget, mainView);
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout" >
<ViewFlipper
android:id="@+id/viewFlipper1">
<TextView
android:id="@+id/header1"
android:text="---Header" />
<TextView
android:id="@+id/header2"
android:text="Other Header" />
</ViewFlipper>
</LinearLayout>