Android List<MiClass> issue, maybe memory?

Hi, I'm having an issue. The endless scroll that I'm implementing each time it goes to the bottom, a method its called that count the list adapter elements and this int I'm using to know where to start loading the results. But the 3rd time I load the list it seems that in memory are, just to say a number, 75 rows instead of 100.

The code I use its

    public class EndlessScroll
            bool IsLoading = false;
            int PreviousTotalItemCount = 0;
            ListView List;
            Action<int> Callback;

            public int TotalItemCount = 0;
            public int visibleThreshold = 15;
            public static int ItemsPerRequest = 50;

            public EndlessScroll (ListView list, Action<int> callback)
                List = list;
                List.ScrollStateChanged += ScrollStateChanged;
                Callback = callback;

            private void ScrollStateChanged (object sender, AbsListView.ScrollStateChangedEventArgs e)
                int last = List.LastVisiblePosition;

                if (IsLoading && TotalItemCount > PreviousTotalItemCount) {
                    IsLoading = false;
                    PreviousTotalItemCount = TotalItemCount;

                if ((last + visibleThreshold) >= TotalItemCount && !IsLoading) {
                    Callback (TotalItemCount);
                    IsLoading = true;

And the callback seems like

    private async void LoadData (int offset)
        RestApiQuery query = new RestApiQuery ();
        query.Offset = offset;
        query.Limit = EndlessScroll.ItemsPerRequest;

        data = await PublicationCollection.Find (query);

           if (offset == 0) {
                   adapter.SetData (data);
               endlessScroll.TotalItemCount = data.Count;
           } else {
               endlessScroll.TotalItemCount += data.Count;
               adapter.AttachData (data);

I can just do much better counting the adapter items in the EndlessScroll but the result is the same, at some point it stop counting or the list doesn't get to the first result when reach the top of the list.

In case that there is another recommendation on how to achieve and EndlessScroll or emulate it (because I know that mobile devices doesn't have unlimited memory).

Sign In or Register to comment.