Search code examples
androidlistviewsmooth-scrolling

How to add items at top of ListView with scrolling without stuck?


I am working on chat application in which I have to manage thousands of chat messages list by paging but my problem is that when I am adding items at the top of ListView adapter during fast scrolling and applying setSelectionFromTop(index, y)...by this my list scrolling getting stuck on index...

 adapter.setData(listChatMessage);
 adapter.notifyDataSetChanged();

 View v = threadList.getChildAt(0);
 int top = (v == null) ? 0 : v.getTop();

 listView.setSelectionFromTop(index, top);

So how can we add items at the top of ListView with scrolling without stuck. What approach should I use.

Can anyone suggest me?


Solution

  • After a long search I found satisfactory post.

    https://chris.banes.me/2013/02/21/listview-keeping-position/