0

I have listview in activity which loads some data from server,initial 5 data are visible in listview and when use4r scroll to bottom a reqest is sent to server and loads 5 more data from server the problem is that when new data are added in listview I want listview to to movew on to 1st data out of 5 data which was loaded from server not to bottom.

m_ListView.setSelection(m_ListView.getCount()-1);
Sandeep
  • 13
  • 4

2 Answers2

0

Ideally, you will have to add the items to the start of your list. Something very similar is already answered at https://stackoverflow.com/a/5903875/775148.

I hope this helps you out. But, it's not the best thing to do. When you are scrolling and new data comes up, the app switches to top and keep doing so everytime you scrolled and fetch new data. Try to do this few times and you may feel that it's not a very good user experience. You keep on scrolling and items gets added to the bottom will give a better user experience.

Community
  • 1
  • 1
android_dev
  • 128
  • 7
0

If you use ArrayList(data of Listview), you can add data to desired position.

ArraList<String> items; // set items
int position; // position that you want

items.add(position, String);

ref: ArrayList

amuyu
  • 236
  • 1
  • 2
  • 9