Where should I use PageViewer?

I implemented the ViewPager and the Fragment number as a child, here each child redefines its own onAttach, onCreateView, onViewCreated and setUserVisibleHint .

In my application, the navigation behavior is random, it will not be in sequence every time. Since the page viewer caches to load an extra child, and this is my problem. I am not sure exactly when I should initialize / free a member of the child class.

A binding suggestion from you guys would be preferable to use PageViwer in this case, or I have to go with the traditional flow of activity for each of the components.

+2
android android-activity android-fragments android-viewpager navigation
Aug 08 '14 at 9:40
source share
3 answers

ViewPager typically used to move an effective horizontal element into an item navigation. Typical use cases:

  • Scrolling related items (such as email messages, images, album songs, etc.).
  • Scrolling between tabs
  • Scrolling back and forth while working with the wizard.

For more information, you can read the Android Swipe Views Sample Design section.

As for the life cycle, it basically uses the same life cycle as any other fragment. The only difference is that life cycle methods can be called a bit later or earlier than you expect, due to fragment caching, ViewPager implements.

I am not sure exactly when I should initialize / free a member of the child class.

You should mainly rely on two methods: onStart() and onStop() . In onStart() you create class members and initialize whatever you want. In the onStop() method, you must uninitialize everything and remove all the listeners that you set to onStart() .

The setUserVisibleHint() method is used regardless of onStart() or onStop() . You better not try to initialize or destroy anything there. You should not consider this a life cycle method because it is not. This is just to give you a hint that your fragment is visible to the user. Here you can start or stop the animation, or request data updates or perform similar tasks. This is the only goal of this method.

The required suggestion from you guys would be preferable to use PageViwer in this case, or I have to go with the traditional flow of activity for each of the components.

If your activity corresponds to one of the points in question, I suggest you use ViewPager . Otherwise, you may consider other options.

Update: Most likely, you will not often override the onCreate() and onDestroy() fragment life cycle methods. Instead, you will use the onCreateView() and onDestroyView() methods. There you can implement the so-called static initialization, the initialization of which does not change while the fragment is still alive. This is a layout initialization and similar tasks.

+2
Aug 14 '14 at 8:49
source share

Using ViewPager

Screen slides are transitions between one whole screen on another and common with user interfaces, such as setup wizards or slide shows.

If you have good knowledge of Fragment than ViewPager is the right component for tools. Since the viewpager provides a place where you can add the runtime of the fragment.

For example, if you want to use TabBar in your project, and viewpager is the right component to use. Because it provides a place where you can add the execution time of a fragment. The tabulator is common in the Android application. It provides a lot of functionality that we can use to add fragment runtime. Facebook using ViewPager to manage the tab. Viewpager ensures the smoothness of your application.

You can download an example from this URL and check whether it is running or not

You can download an example here.

+1
Aug 12 '14 at 16:41
source share

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. 

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

+1
Aug 13 '14 at 12:23
source share



All Articles