CoDe
CoDe

Reputation: 11146

Where should use PageViewer?

I have implemented ViewPager and number of Fragment as child, here every child override own onAttach, onCreateView, onViewCreated and setUserVisibleHint.

In my app navigation behaviour is random, it not be in sequence every time. Since page viewer perform caching to load extra child, and this is what my problem is. I am not sure exactly when I should initialise/release member of child class.

Required suggestion from you guys, will it be preferable to use PageViwer in this case or I should go with traditional activity flow for each of component.

Upvotes: 2

Views: 1102

Answers (3)

sergej shafarenka
sergej shafarenka

Reputation: 20406

ViewPager is typically used for move efficient horizontal item to item navigation. Typical use cases would be

  • Swiping through the related items (e.g. emails, images, songs of an album, etc.)
  • Swiping between the tabs
  • Swiping back-and-forth in a wizard-like activity

For more details you can read a section about Swipe Views Android Design pattern.

Regarding the lifecycle, it basically uses the same lifecycle as any other Fragment. The only difference is, that lifecycle methods can be called a bit later or earlier than you expect, because of fragment's caching ViewPager implements.

I am not sure exactly when I should initialise/release member of child class.

You should basically rely on two methods: onStart() and onStop(). In onStart() you create class members and initialize everything you want to. In onStop() method you should deinitialize everything and remove all listeners you set in onStart().

Method setUserVisibleHint() is used independently of onStart() or onStop(). You shoud better not initialize or destroy anything in there. You must not consider it to the a lifecycle method, because it's not. It's there just to give you a hint, that your fragment is visible to the user. Here you can start or stop animation, or request data update or perform similar tasks. This is the only purpose of this method.

Required suggestion from you guys, will it be preferable to use PageViwer in this case or I should go with traditional activity flow for each of component.

If your activity fits into one of the points mentioned about, I would suggest you to use ViewPager. Otherwise you might consider other options.

Update: Most likely you won't override onCreate() and onDestroy() lifecycle methods of a fragment very often. You will use onCreateView() and onDestroyView() methods instead. There you can implement so called static initialization, the initialization which doesn't change while a fragment is still alive. This is layout initialization and similar tasks.

Upvotes: 2

mdsaleem1804
mdsaleem1804

Reputation: 110

ViewPager

  It is an widget 

  Allows the user to swipe left or right to see an entirely new screen. 

  Easy  to show the user multiple tabs

  Dynamically add and remove pages (or tabs) at anytime.

To Read More: http://architects.dzone.com/articles/android-tutorial-using

Upvotes: 1

Ramkailash
Ramkailash

Reputation: 1850

ViewPager Usages

Screen slides are transitions between one entire screen to another and are common with UIs like setup wizards or slideshows.

If you have good knowledge in Fragment than ViewPager is right component for implements. Because viewpager provide a place which you can add fragment runtime.

For eg. If you want to use TabBar in your project than viewpager is right component for using. Because it's provide a place which you can add Fragment runtime. Tabbar is common in android application. It's provide lot of functionality inbuild we can use to add fragment runtime. Facebook app using ViewPager to manage tab. Viewpager provide smoothness of your application.

You can Download example from this url and check your requirement fulfill or not

You can download the Example here

Upvotes: 1

Related Questions