1

I have a custom listview(with two image and 5 textviews) in which I have to show more than 200 data when I load it at first time with all data then it returns out of memory exception, to resolve the same problem I want that when we scrolled down the listview till the last item of the list then it app again adds more data to the same list. It running as same till we have got all the data on the list view. Please don't tell me to use EndlessAdapter because Endlessadapter always downloading the items after each 10 seconds. Which returns also the outof memory after some time.

Thanks in advance.

Sanat Pandey
  • 4,081
  • 17
  • 75
  • 132
  • "Please don't tell me to use EndlessAdapter because Endlessadapter always downloading the items after each 10 seconds" -- no, it is not. **Your code** is "always downloading the items after each 10 seconds". There is no code in `EndlessAdapter` that does *anything* "each 10 seconds". I explained where your problems generally lie in my answer to your last question: http://stackoverflow.com/a/11023432/115145 – CommonsWare Jun 14 '12 at 20:56
  • Ok I agree with you but tell me where is the problem in the code? and how it will be resolved? – Sanat Pandey Jun 14 '12 at 21:28
  • I answered that already, in my answer (http://stackoverflow.com/a/11023432/115145) to your other question (http://stackoverflow.com/questions/11022562/endless-adapter-always-running-to-download-data-in-background). – CommonsWare Jun 14 '12 at 22:11
  • R u telling about the lazyadapter mentioned in the appendCached method? – Sanat Pandey Jun 14 '12 at 23:32
  • I have no idea what you are talking about. – CommonsWare Jun 14 '12 at 23:44

5 Answers5

0

assign a List http://developer.android.com/reference/java/util/List.html to your addapter then you can call item.add and item.remove

Alexander Fuchs
  • 1,358
  • 3
  • 19
  • 36
0

please try this

endless listView

Thanks

Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
0

about out of memory , there is no way that 5 imageViews and 5 textViews will cause out of memory . you are probably saving all of the 200 images together instead of using some sort of caching (like softreference and LruCache) . the whole point of the adapter is to show tons of items (not at the same time , of course) using minimal memory . you can see that even the play store (which i still like to call android market) app uses memory cache if you play enough with scrolling ...

for more information about listview, watch this

you might also want to read more about handling images here .

anyway , you can take the getView as a trigger (using the position parameter compared to the getCount() value) to when to load more items and then update the adapter using notifyDatasetChanged (and update the getCount() value) .

android developer
  • 114,585
  • 152
  • 739
  • 1,270
0

I'd recommend that every time a user scrolls you check the position of the first element of the ListView.

ListView.getFirstVisiblePosition() 

If it's close to the amount of the elements in your list you can add items to the bottom of the list and remove the ones from the top of the list.

libjup
  • 4,019
  • 2
  • 18
  • 23
0

I did something like this to load in more elements when the user scrolled down on an ExpandableListView once.

myListView.setOnScrollListener( new OnScrollListener() 
            {
                public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) 
                {
                    int lastVisibleElement = firstVisibleItem + visibleItemCount;
                    if(lastVisibleElement == totalItemCount)
                    {
                        //Load elements
                        myListAdapter.notifyDataSetChanged();
                    }
                }
MAV
  • 7,260
  • 4
  • 30
  • 47