Based on FragmentPagerAdapter, I have inflated my view pager and I can see my items in each page. How to know, which page is clicked by user to direct him/her see detail of information?
Thanks
As far as I know, there is no way to get the current displayed Fragment by the FragmentPagerAdapter, so what I can suggest is keep an position member variable for each Fragment that is added in the pager so you can use that to know which fragment is clicked.
Related
I am using ViewPager with 4 pages. I need a code to navigate to the first page on specific events. Any idea how? The PagerAdapter has the methods setPrimaryItem, but I am uncertain how to use it.
Another relevant question is how to trigger swiping the pager through code, I could use that to swipe all the way to the needed view, and I imagine it will also look better.
Just use mViewPager.setCurrentItem(1), this method will navigate to that page with the swipe animation.
once again, I am following this tutorial: androidhive - tab layout with swipe able views . All 3 fragment tabs are loaded with different information and logic and layouts. I would like to refresh each fragment when their tabs have been clicked as it auto loads the fragments from start as it uses the view pager. Is there any simplest way out that I could load only a/1 fragment using view pager? Or to reload the fragments? Thanks for your help!
Try to add this to your viewpager:
MY_VIEWPAGER.setOffscreenPageLimit(0);
Check out the documentation.
Pages beyond this limit will be recreated from the adapter when needed.
The limit of 0 will cause a recreation of the fragment when you open a tab.
while using View pager, I face a strange problem.
In my project i have three fragment in a view pager, but while loading the second fragment by swiping from left to right , the OnCreate of third Fragment is automatically calling.in onCreate method i called an Api for getting some data.hence the Api is also called.Normal scenario is like that it only called while loading third fragment by swiping from left to right.
Thanks in Advance
View pager works same as listview.
It have same buffer of fragments to increase the UI experience.
so it creates fragments in advance and show to he user when asked.
so use http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html
for your purpose.
Thanks
I have a problem that, I have to implement horizontal swipe view as a paging system and each page shows data from the server, means each page shows dynamic data at run time. I think it is possible with View Pager but in View Pager there is no any fixed layout which is shown on particular page, So, firstly how can we do that, secondly in View Pager all views should be predesigned or preimplemented or we can say that Number of Views we must know. But when we want to take it dynamic when user swipe a page then it goes to next page but progressbar will appear to show the data for corresponding page. So, how can we do this also? Please suggest me any solution regarding the same.
View Pager:
View Pager Demohttp://android-developers.blogspot.in/2011/08/horizontal-view-swiping-with-viewpager.html
Thanks in advance.
Have you tried to implement
viewPager.setOnPageChangeListener(this);
to detect page changement and so loading the page content
The solution isn't in ViewPager but in your custom PagerAdapter. You must subclass the PagerAdapter and add a method to add content to your adapter and call in this method the method notifyDataSetChanged :
public void addPage(Object page) {
// Add page to the arraylist of adapter
notifyDataSetChanged();
}
How to put Expanded List inside a Fragment Tab?
I have 3 fragments in one page, The 2nd Fragment consist of two tabs,I want to put an expanded List inside the second tab.please help ,Thanks :)
Correct me if I am wrong in assuming that you are using ListFragment to show the lists. If you want to use a ExpandableListView you are going to have to implement it yourself inside a normal Fragment since there is no ExpandableListFragment implemented in the APIs.
Here is a link to Android's documentation on how to implement it: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
Hope it helps.