1

I want to implement a List View in Fragment. Size of the list can be more than 1000 which includes images in left and name and type will be right. I am able to implement CustomArrayAdapter and List View but i don't know how to load only specific number of items or only those which are visible. I want that if user scroll down then only hit the server and load the images and data.

How can i implement this kind of List View in Fragment?

I don't know much about andorid. Please help me out to solve this problem.

Thank in advance

user3154663
  • 291
  • 2
  • 18
  • I don't know why my question get down voted. – user3154663 May 19 '14 at 10:42
  • Try this: http://stackoverflow.com/questions/5967994/how-to-populate-a-listview-asynchronously, this _Making ListView Scrolling Smooth_: http://developer.android.com/training/improving-layouts/smooth-scrolling.html and this _Loading Views On Demand_ :http://developer.android.com/training/improving-layouts/loading-ondemand.html – ElBaulP May 19 '14 at 10:46
  • you have to use pull to refresh for this – Meenal May 19 '14 at 10:48
  • i found simmilar question [here](http://stackoverflow.com/questions/1080811/android-endless-list) – Imtiyaz Khalani May 19 '14 at 10:49
  • @MeenalSharma i want to load data when user scroll down the list not refresh the list i mean not pull down – user3154663 May 19 '14 at 11:28
  • please see my editted answer – Meenal May 19 '14 at 11:56
  • @MeenalSharma i want to implement endless list view. Not pull to refresh. – user3154663 May 19 '14 at 12:35
  • what you want is called lazy loading. for images i know a few libraries like 'URLImageViewHelper', 'UniversalImageLoader'... looking for such things for other type of data. – Kaustuv May 19 '14 at 13:07
  • @kaustuv but those libraries only for images lazy loading not for the data. – user3154663 May 20 '14 at 04:51
  • @Kaustuv i need endless List view means display only 10-20 item then when user will scroll down then show loding and then load rest of 10-20 items. Like google-play, facebook etc – user3154663 May 23 '14 at 18:22
  • hey i think this might work. suppose you have an array list of 10 items to show. When user scrolls use listView.getLastVisiblePosition()==dataSource.size() to get to know when user reaches end of list. Then do your network call to get new set of data, add this to the old data source of your list view and call notifyDataSetChanged(). This way new items will get added at end of list – Kaustuv May 24 '14 at 11:24

2 Answers2

0

The listview class has a couple of useful methods to deal with that:

 int lastItem = listView.getLastVisiblePosition();  

 int firstItem = listView.getFirstVisiblePosition();

What you could do is load an appropriate batch of data from the server (say 100 items), then override the method onScoll() of the listview to keep track on what are those values over time, when the user arrives to the end of the batch (say, the position 100), you can load the next batch and notify the adapter that the list has changed.

AMC
  • 120
  • 8