ViewPagerIndicator not updating after setCurrentItem() - android

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.

Related

Android best practices for fragment animations

I have activity with two tabs. Both tab uses different fragments. When a particular event occur like user click on item, I am opening another fragment in same activity.
I know how to add fragment dynamically and I also know how to animate it.
Here, how I added fragment to frameLayout in my activity:
transaction.setCustomAnimations(R.animator.object_slide_in_up, R.animator.activity_hold)
transaction.add(R.id.flSellerHome, fragment)
transaction.commit()
Everything works fine in emulator and newer phones. I have tested with emulator with api 25, it works fine now flickering occur, When I am testing it with real device with api 23 it flicker little, so it doesn't affect, after then when I tested it with api 19, it flickers too much.
So my question is any best practise for doing animation.
Notes
My third fragment which is dynamically added contains recylerview with around 20 items from local db, and I also done db fatching in background thread.
No loads on main thread. recyclerview is also simple with one Image and three texts.
Image is also loaded using Glide and also I have override function of glide**
any help is appreciated..
I found problem is with recyclerview data updation.
I am loading data in background thread, but when notifying recyclerview, it stucks for small amout of time.
So what I have done is. I have delayed data load for same amount of time which is for animation.
I don't know it is good idea or bad idea. But it is too late for my project so I used this workaround.
I wanted to write comment to your answer, but I dont have enough rep, but I want try to advice you something, so sorry for this.
I am loading data in background thread, but when notifying recyclerview, it stucks for small amout of time.
Try to start loading, which you did, after click and show simple ProgressBar, and when data is loaded, hide progress bar, set info to your fragment and then show fragment. Then you will have all data wich you need in fragment when it is attached and can put it (data) to your adapter.
It have to look good.
If it occurs only for API 19 and lower, it may be a lack of performance from the device.
Maybe the problem do not come from Fragments and Animations, but from another functionality which slow down the UI thread. By functionality, I mean the way your fragments communicate together. Do they share a huge amount of data ? Or heavyweight datas ? If so, you should use Async Tasks or Threads.
Good luck !

Make a loop in PagerAdapter

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

Android: Is there any way to animate fragment deletion in a ViewPager?

I've implemented a cursor backed ViewPager, where I'd like to enable the user to add or remove items. However, deleting a page causes janks in the viewpager.
I'm currently manually scrolling to the next page using viewPager.setCurrentItem(NEXT_PAGE_NO, true); after deletion and scrolling back in the adapter after updating the data set. This does work, but only half of the time.
Is there any proper way to animate it? A solution or a workaround, both will do.

Why ViewPagerIndicator calculate all titles every time

I am using ViewPager and ViewPagerIndicator (here). WHen I debug, I see that the ViewPagerIndicator call getPageTitle() to get title of all pages every time I scroll the Viewpager. Now I have more then 1000 pages. So, when I scroll, the titles aren't smooth any more. Did you face this problem before? Please share with me the solution. Any recommend are welcome.
Thanks a lot.
I have the same issue, I have a ListView with an ArrayAdapter. Each time I scroll back to the page, the list keeps recreating it self and expands.. I solved it with a simple boolean to check weather the list have items or not, but that's not the optimum solution. I think there is something in OnPageChangeListener from android.support.v4.view.ViewPager package that ViewPagerIndicator doesn't address.

Android load listviews at end of scrolling

I want to implement functionality where a listview loads a set number of views, but at the end of the scrolling it has a spinner in that view, while it loads more views
the official android twitter app has something like this, where it shows you old messages from your timeline but at the bottom of the list it will load more after running a spinner. you can still scroll up and down while this thread is happening without breaking anything
how would this be done? insight appreciated
i think by spinner u mean blocking screen ?
anyways what u need is pretty common, just search for listview implementation in android
here is one of the link i still had:
http://blog.zjor.ru/2010/12/loading-list-data-asynchronously-in.html
also check this if u really want to go to that extent ;)
https://github.com/commonsguy/cwac-endless
basically, it would probably be something like:
Load some data (use a limit)
When you enter the bindView of your last element, change your limit (may be by joining the cursor to another one)

Categories

Resources