简体   繁体   English

recyclerView 列表中的最后一项

[英]The last item in the recyclerView list

How can I display a message to the user after scrolling the recyclerview items and viewing the last item in the list?滚动 recyclerview 项目并查看列表中的最后一项后,如何向用户显示消息?

The code below does not work下面的代码不起作用

recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener(){
    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
        super.onScrolled(recyclerView, dx, dy)


        val count= recyclerView.layoutManager?.itemCount

        if (customerModels.size==count){
            Toast.makeText(applicationContext,"true",Toast.LENGTH_LONG).show()

        }

    }
})

This is what I usually use when I want to check if the user is reached to the bottom of the recyclerView当我想检查用户是否到达 recyclerView 的底部时,这是我通常使用的

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        LinearLayoutManager lm=LinearLayoutManager.class.cast(recyclerView.getLayoutManager());
        int items= lm.getItemCount();
        int last = lm.findLastVisibleItemPosition();

        boolean bottom= last+ 5 >= items;
        if (items> 0 && bottom) {
            //you have reached to the bottom of your recycler view
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM