再次插入数据时,Recyclerview会自动向上滚动

Mad*_*vat 4 android arraylist recycler-adapter android-recyclerview

我遇到了一个问题,当我将数据添加到数组列表然后将其添加到适配器之后,当我将其设置为recycleler视图适配器时,它会自动跳转到顶部我如何能够阻止它,就像我想在虚拟空间中添加数据一样我也尝试过使用 -

runOnUiThread(new Runnable() {
                                public void run() {
                                    innerAdapter.notifyDataSetChanged();
                                }
                            });
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我怎么解决呢?

添加一些代码以便向上滚动

if (isScrollUp) {
                            isEnable = true;
                            userChats.addAll(0, model.data);
                                                       innerChatAdapter.notifyDataSetChanged();
                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    nnerChatAdapter.notifyItemInserted(0);
                                    recyclerView.smoothScrollToPosition(0);
                                }
                            }, 1);
                        }
Run Code Online (Sandbox Code Playgroud)

ash*_*ish 6

Hello,如果要在调用notifyDataSetChanged()之后向adapter.Add下面的方法添加数据后向下滚动.

 new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mRecyclerView.smoothScrollToPosition(new_data_size);
            }
        }, 1);
Run Code Online (Sandbox Code Playgroud)