android: smoothScrollToPosition() not working corr

2019-01-17 05:24发布

I'm trying to smoothly scroll to last element of a list after adding an element to the arrayadapter associated with the listview. The problem is that it just scrolls to a random position

arrayadapter.add(item);
//DOES NOT WORK CORRECTLY:
listview.smoothScrollToPosition(arrayadapter.getCount()-1);

//WORKS JUST FINE:
listview.setSelection(arrayadapter.getCount()-1);

7条回答
Luminary・发光体
2楼-- · 2019-01-17 06:28

Do you call arrayadapter.notifyDataSetChanged() after you called arrayadapter.add()? Also to be sure, smoothScrollToPosition and setSelection are methods available in ListView not arrayadapter as you have mentioned above.

In any case see if this helps: smoothScrollToPosition after notifyDataSetChanged not working in android

查看更多
登录 后发表回答