Add new items to top of list view on Android?

后端 未结 7 1530
梦谈多话
梦谈多话 2020-11-30 03:19

Android has the transcript mode to allow to automatically scroll a list view to the bottom when new data is added to the adapter.

Can this be somehow reversed so tha

7条回答
  •  不知归路
    2020-11-30 03:52

    instead of this:

    items.add(edittext.getText().toString());
    adapter.notifyDataSetChanged();
    

    you should try that (works for me):

    listview.post(new Runnable() {
                @Override
                public void run() {
                    items.add(0, edittext.getText().toString());
                    adapter.notifyDataSetChanged();
                    listview.smoothScrollToPosition(0);
                }
                });
    

提交回复
热议问题