This can be done by providing your appwidget with a state that determines the page displayed on it. And assign the broadcast to the buttons to change the state.
- Send a broadcast when the PendingIntent buttons are pressed .
- receiver listen to the broadcast and track the status (page)
- Update the application depending on the current state
Here is an example of incomplete code:
RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.widget_weather); // update appwidget remoteviews depending on state (ie which page to show) remoteViews = populateViews(remoteViews, mState); // set next button Intent intent = new Intent(MYBROADCAST_NEXT); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, flags); remoteViews.setOnClickPendingIntent(R.id.appwidget_btn_next, pendingIntent); // set prev button intent = new Intent(MYBROADCAST_PREV); pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, flags); remoteView.setOnClickPendingIntent(R.id.appwidget_btn_prev, pendingIntent); // update the AppWidget ...
Hope this helps you achieve what you want.
source share