Make a loop in PagerAdapter - android

I want to loop my Viewpager and Im using the PagerAdapter extension. Everything I found in the net was an example with Fragments.
I want to solve this with a normal pageradapter. So When I Swipe from 1st view to left I want to be in the last View , and when I swipe from last view to right I want to change to 1st.
How can I solve this in an easy way (maybe without any libaries) ?

You can use the viewpager's setCurrentItem() method for achieving such functionality. This method takes the position (zero-based) of the view you want to navigate to.

https://github.com/TobiasBuchholz/CircularViewPager
I used this library, but there some problems in it when you try to show many circular views simultaneously

Related

How to create App Into with images and a pager below?

I want to have a bunch of images that show how my app works and have a dot-type pager at the bottom, like the example below. What UI Element should I be using?
Is Android ViewPager suitable for this? how will be adding the small circles below which act like page numbers.
EDIT: After I posted this question, I found this library. Would like feedback on how to do this from scratch.
Actually, if you look thought the code at https://github.com/JakeWharton/ViewPagerIndicator you can get a nice feedback on how to do it from scratch. The lib uses a custom View , but you can emulate this kind of behavior with some existent views, for instance. Basically:
Create a LinearLayout below your ViewPager. Set the orientation to horizontal;
Put some RadioButtons in it (you can do it dynamically based on your adapter size);
In your Activity, Fragment or whatever set a PagerListener for your ViewPager;
This listener is provided by the ViewPager API and you can check and uncheck your RadioButtons according to the position in the ViewPager with the method onPageSelected(int position), for instance.
There you go, a (very) basic ViewPagerIndicator.

how to prevent creating same layout everytime while using fragments and viewpager?

I have a viewpager that holds 3 different fragments and all fragments has tablelayout which loads dynamicaly. (while saying dynamically, I never try to reach any dataset, I take dataset from bundle already, what I do is just iterate dataset and during this process creating tablerows, textviews and inserting them into tablelayout by one by, so the issue is only creating view as dynamicaly)
My problem is while swiping between fragments it takes a while. I noticed it does that filling operation I mentioned above in oncreateview everytime.
What I want to do is it should create tablelayout just once at the begining and return it everytime as view if fragment would be selected.
When I try that fragments view appears only once and after swiping nothing appears.
I couldnt sleep and I am writing these via my cellphone, so I cant share what I did at the moment but I hope youll get what I want to do and maybe direct me in a good way.
You can use:
myViewPager.setOffscreenPageLimit(3);
which will keep a fragment around once it has been loaded.
Also, you really should use a ListView instead of building out TableRows. This will scroll much smoother and load faster.

ViewPagerIndicator not updating after setCurrentItem()

I'm trying to make an app for a local event to allow referees to quickly judge performance. Right now, I'm using a view pager that will not allow them to advance the page without inputting the results necessary in the page. I also have the page auto advance after they have input results.
I also have a ViewPagerIndicator (the line one) that doesn't update after setCurrentItem() is called. I tried calling notifyDataSetChanged() after setCurrentItem(), but that didn't seem to help.
Page advancing code:
if(pager.getMaxPage()<pager.getCurrentItem()+1){
pager.setMaxPage(pager.getCurrentItem()+1);
}
pager.setCurrentItem(pager.getCurrentItem()+1);
pager.getIndicator().notifyDataSetChanged();
I extended viewpager to store it's indicator.
Edit: To be clear, if I comment out the above code, and allow it to advance by swiping at all times, the indicator updates fine.
Ok, dumb mistake. If anyone sees this and has this issue, set your onPageChange listener to your indicator, not the ViewPager itself.

ViewPager and Listview

I am making an android app where I have listview being populated using fedor's Lazy Loading solution. This happens after I do some work in an async task and on completion of which my listview gets populated. The listview contains an ImageView and a TextView for every single row. I want to use the ViewPager implementation where on one page, I have the listview and on selection of an item in the listview, the user gets shifted to another page on the right (or maybe he can swipe to another page) where he can get the detail screen of the ListView Item. How is this possible. Do i need to use ViewPager or some implemenation of Tabs. Also if someone can refer me to some good tutorial related to ViewPager and How to implement Activities inside viewpager, that would be great!
Thanks in advance!
If you looking for the swipe than you should use GestureListener interface...
you can find this at following link
I had recently done the swiping of ListViews using viewPager it works very well
Follow this tutorial
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/
You can read this from android developer site also for better understanding http://developer.android.com/training/animation/screen-slide.html
Please feel free to ask any doubts I had done this recently
Use Fragments within View Pager(not activities)
Use ViewPager if it is a listView and some other screen for the swipe.
for detail view on selection of list item, use a separate fragment and load it in the container.
Just:
Set a background that support the selected state in your list item layout, like:
android:background="?android:attr/activatedBackgroundIndicator"
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
FYI: http://cyrilmottier.com/2011/08/08/listview-tips-tricks-3-create-fancy-listviews/ and http://android-developers.blogspot.mx/2008/12/touch-mode.html

ViewPager + recycling views?

I'd like to create a gallery of photos that swipe left and right. At first I took a look at Gallery, but it's marked as deprecated.
http://developer.android.com/reference/android/widget/Gallery.html
We're told to try ViewPager instead. But the PagerAdapter class doesn't handle recycling of views for us (like a standard ListView), does it?
http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html
Is it up to us to build the recycling mechanism?
Thanks
But the PagerAdapter class doesn't handle recycling of views for us
(like a standard ListView), does it?
No, and I think it's because it was built assuming you are using different layouts for each of the page.
Also, as it is not being scrolled as fast as a ListView (you cannot "fling" a ViewPager to skip multiple pages), I think it doesn't need to have to recycle.
This HorizontalListView is great, i used it to do exactly what you want.
see the link in the edit on this question The link in the Edit, and the answers give you some possible ways to solve.
There is also a HorizontalListView online somewhere if you search for it that makes a fine replacement for Gallery and does recycle its views.

Categories

Resources