3

I have a ViewPager that contains ImageViews downloaded from the net and it slides just fine when my ListView (in another separate layout) is not initialized.

But the problems start when my ListView is created. The ViewPager still "slides" but only slides about 1/4 of the way, lags, then loads the next ImageView correctly.

All of the network and bitmap operations are done using AsyncTask. I've also used the RemoteImageCache API from Singly API which works pretty well.

Any ideas as to why ViewPager's swipe is lagging?

Ron
  • 1,721
  • 1
  • 19
  • 43
  • 1
    Maybe your adapter's getView() is being called constantly while swiping? Place a log there and check what's up. Also, are you recycling your views via a ViewHolder for the adapter? – npace May 29 '13 at 14:50
  • Are you talking about the ListView adapter? Yes, I already implemented the viewholder pattern for it. And yes, the Log confirms that getView is getting called after each swipe. Is there a way to control this? – Ron May 30 '13 at 06:54
  • Found the solution: http://stackoverflow.com/questions/11186004/yet-another-getview-called-multiple-times. The listview's height and width must be fixed or else it keeps calling getView. – Ron May 30 '13 at 07:10

3 Answers3

4

The slow down was caused by the ListView calling getView more than necessary (more than 3x per item in my list).

According to this solution, the ListView's width and height must be given specific values and not wrap_content or else getView() will be called multiple times.

Community
  • 1
  • 1
Ron
  • 1,721
  • 1
  • 19
  • 43
0

it's just because of list view scroll is conflict with view pager scroll..

if you want to know about this just set list view visibility gone don't remove code listView.setAdapter(adapter) then try view pager will slide properly.

Chirag Sheta
  • 149
  • 1
  • 12
0

Recently (2020), must be to implement a ViewHolder class to you get speed, or, refactoring with RecyclerView, it depends of the size of your list and the time that you have to execute this methods, like my software was already production stage, i preferred use ViewHolder class, the speed gain came to be 40%, sufficient to me, if you need the more speed, must be to use RecyclerView (refactoring your listview, edit .xml, your adapter, use Linear or Grid layout manager...).

luke cross
  • 321
  • 1
  • 2
  • 19