• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Swiping between activities

Guy Yafe

Lurker
Hi All,
I am a completely newbie at Android development and would like to consult about the proper design.
The application is kind of a book. The first screen is an opening screen (ImageView), and clicking on it will lead to the table of contents.
The table of contents, as any of the other chapters is a separate activity. It has a LinearLayout that contains a Header (TextView) and a chapters list (ListView).
The chapters themselves also built the same, so each item in the list is a different paragraph.
Clicking an item on the chapters list (in the table of contents) will switch to the activity with the relevant chapter.
Swiping from left to right on a certain chapter (including the table of contents) will switch to the next chapter. Swipe left will lead to the previous one. Note that there is no mistake here: Text direction is RTL.
At first, the swiping only worked when the swiping was performed on an empty areas of the screen, and not on the contents of the ListView. So in order for the swipe to work on the items as well, I have performed the following (after consulting some guides in the web):
1. I have added a GestureDetector member to the activity.
2. I have initialized the above member with a private class overriding GestureDetector.SimpleOnGestureListener and implementing onFling. It is a straight forward implementation: Just calculating the direction of the swipe and determining the next chapter.
3. Clicking an Item: I have added the current activity to the ListView by setOnItemClickListener. This activity implements onItemClick by switching to the correct chapter.
4. Swiping: I have added to the ListView, by setOnTouchListener, an interface which implements onTouch by calling the GestureDetector member.

The problem is that this doesn't work as expected:
a. Scrolling the list doesn't work well: I have assumed that like any other application, swiping the finger will start a fast scroll that will slow down until stopped. Instead the scrolling is fixed according to the finger movement: As long as the finger moves, the list is scrolled and the scroll is stopped the moment the finger is raised from the screen.
b. Looks like overriding both setOnItemClickListener and setOnTouchListener causes trouble. If I swipe right on one of the chapters in the list in the table of contents (say chapter 7), I will get to the first chapter as expected, but clicking the back button, will return me to the table of contents activity and the same chapter 7 item will be highlighted.

I will be glad for some guidance: I guess I have completely missed something here.
Some of the guides and examples in the web were using fragments, so maybe I should consider using fragments instead?
Maybe it is wrong to use a list with an element for each paragraph? Is it better using a single TextView into which I will dynamically load the text?

This is the relevant code:
[Java] public class ContentTableActivity extends Activity implements OnItemClickListene - Pastebin.com
 
I would definitely look into using a ViewPager with Fragments. The swiping side to side works great with it. You could still use a list view in the fragments for the sections of the chapters.
 
Back
Top Bottom