views:

76

answers:

2

I'm developing an Android Application that has three very similar Activities. I would like the user to be able to switch between them by swiping left and right on the screen. This is how I managed that up to now:

I followed this post

Then I changed the method onSwipe() in this way:

@Override
 public void onSwipe(int direction) {
  Intent intent = new Intent();

  switch (direction) {

  case SimpleGestureFilter.SWIPE_RIGHT:
   intent.setClass(this, TodoTodaySheet.class);
   break;
  case SimpleGestureFilter.SWIPE_LEFT:
   intent.setClass(this, TrashSheet.class);
   break;

  }
  startActivity(intent);
 }

It works but I'm not completely satisfied with this. Moreover, I don't know if this is the correct approach.

I would like to have a behavior like the one on Home apps, when switching desktop. Therefore I would like a smoother animation and the appearance of the called activity from the right direction, eg. from the left side of the screen when swiping on the right.

Any hints? Thank you very much.

A: 

While it's probably best to have them as three separate Activities, I've seen people use a ViewFlipper to achieve a similar effect in a single Activity.

Here's a link with a little more information about it: http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html

Faisal
Thanks for this. I would like to avoid this approach, since the three activities (that are listactivities) are similar but doing a quite heavy task (retrieving things from database etc)
bodom_lx
A: 

The home screen doesn't scroll between activities it only scrolls between differing views as you can see in its' source code (line 298 is where the screens are changed).

If you're switching between activities you're at the mercy of the users configuration & the devices abilities as to what happens to the display during the transition, so there isn't a lot you can do.

Al Sutton
Therefore the only way to achieve this is to use a ViewFlipper as Faisal suggests, or to have a TabView and some gestures to switch between activities, like the News app does.
bodom_lx
Using a ViewFlipper would constrict you to using a single Activity which has implications for how the OS manages your application (e.g. the OS is left with a kill all or nothing choice when it cleans resources).
Al Sutton