RecyclerView scroll to position when a new item is added

后端 未结 7 1650
南笙
南笙 2020-12-31 03:18

I want my RecyclerView to scroll to the bottom when a new item is added to the list. Below is my code:

RecyclerView.LayoutManager layoutManager = new LinearL         


        
相关标签:
7条回答
  • 2020-12-31 04:04

    Maybe this will help someone

    @Override
    public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
        if (pingAdapter != null) {
    
            Ping ping = dataSnapshot.getValue(Ping.class);
            pingAdapter.pings.add(ping);
            recyclerView.smoothScrollToPosition(pingAdapter.getItemCount());
    
            pingAdapter.notifyDataSetChanged();
        }
    }
    
    recyclerView.smoothScrollToPosition(pingAdapter.pings.size());
    

    is even faster

    0 讨论(0)
提交回复
热议问题