how to maintain scroll position of listview when it updates

后端 未结 6 1171
[愿得一人]
[愿得一人] 2021-02-05 05:32

I have read plenty of examples ,but if I wish to maintain my scroll position after a ListView is updated from JSON ,then can I do that without using an

6条回答
  •  半阙折子戏
    2021-02-05 06:16

    For overall picture:

    In your API response callback, call this function(example) below:

    MyAdapter mAdapter;
    ArrayList mUsers;
    
    private void updateListView(ArrayList users) {
        mUsers.addAll(users);
        if(mAdapter == null) {
            mAdapter = new MyAdapter(getContext(), mUsers);
            mListView.setAdapter(mAdapter);
        }
        mAdapter.notifyDataSetChanged(); // Add this one
    }
    

提交回复
热议问题