4

I'm having trouble trying to find any tutorials on how to make a paging app widget like the ones found in Facebook, Twitter and FriendCaster.

I could use the new Android 3.0+ tools with an adapter, however that would be difficult to test as I don't have any devices capable and my computer isn't either.

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
Joe Simpson
  • 2,546
  • 4
  • 30
  • 46

2 Answers2

3

This can be done by giving your appwidget a state, which defines the page it currently shows. And assign broadcast to the buttons to change state.

  1. Send broadcast when buttons are clicked using PendingIntent.
  2. Have a receiver listen to broadcast and keep track of state (page)
  3. Update the appwidget depending on the current state

Here is some incomplete code example:

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 to achieve what you want.

J.G.Sebring
  • 5,934
  • 1
  • 31
  • 42
1

You can use the compatibility package, it is backwards compatible. The minimum API level is 4, which is Android 1.6

http://developer.android.com/sdk/compatibility-library.html

Use ViewPager, there's plenty of examples for it. http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html

Maximus
  • 8,351
  • 3
  • 29
  • 37