Anyone familiar with android gallery view pager?
-
I am currently doing my college project on android application. Basically i use viewPager to slide between several images. Lets say image 1,2,3,4. However if i close it at image 3, and when i open the app again, it does not go to the last image shown previously which in this case 3. It will always start with image 1. Anybody knows about this? how to make it show last image seen when we return to open the app?
-
Answer:
I think there are three ways to do it. http://developer.android.com/reference/android/content/SharedPreferences.html is what will come handy. Storing the position of the current page of ViewPager and then retrieving it back when application is resumed through onResume() method. The solution is a bit tricky but here is a link to successful explanation and implementation. http://d.hatena.ne.jp/yohpapa/20130319/1363708468 When the FragmentPagerAdapter adds a fragment to the FragmentManager, it uses a special tag based on the particular position that the fragment will be placed. This tag can act as a saved state and then the fragment state can be restored back. http://stackoverflow.com/questions/7951730/viewpager-and-fragments-whats-the-right-way-to-store-fragments-state ViewPager has methods called http://developer.android.com/reference/android/support/v4/view/ViewPager.html#getCurrentItem%28%29 and http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setCurrentItem%28int%29 Put the integer returned by get method before closing app and save it in Shared preferences. On starting app set the saved value by using set method.
Akash Sharma at Quora Visit the source
Related Q & A:
- How to replace a fragment of view pager with other new fragment in android?Best solution by Stack Overflow
- Is anyone familiar with the route to Queretaro from Minnesota via Laredo, Texas?Best solution by Yahoo! Answers
- Is anyone familiar with the SpiderWeb Marketing System?Best solution by warriorforum.com
- Is anyone familiar with this website?Best solution by Yahoo! Answers
- Anyone familiar with the internet by satellite?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.