RecyClerview加载更多最短和简单的方法?
我想加载更多数据以显示10个数据加载后的回收视图。下面的示例。我很累。我无法理解解决方案。我想要一个简单的解决方案。
commentpost.java
public void showData(){
//view Comment
progressDoalog = new ProgressDialog(CommentPost.this);
progressDoalog.setMessage("Loading....");
progressDoalog.show();
/*Create handle for the RetrofitInstance interface*/
Call<List<Comments>> call = service.getComment(audioPath);
call.enqueue(new Callback<List<Comments>>() {
@Override
public void onResponse(Call<List<Comments>> call, Response<List<Comments>> response) {
progressDoalog.dismiss();
generateDataList(response.body());
}
@Override
public void onFailure(Call<List<Comments>> call, Throwable t) {
progressDoalog.dismiss();
Toast.makeText(CommentPost.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
/*Method to generate List of data using RecyclerView with custom adapter*/
private void generateDataList(List<Comments> CommentsList) {
recyclerView = findViewById(R.id.recyclerView);
adapter = new CommentAdapter(this,CommentsList);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(CommentPost.this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
//latest message
recyclerView.scrollToPosition(adapter.getItemCount() - 1);
}
适配器:
@SuppressLint("RecyclerView")
@Override
public void onBindViewHolder(CommentAdapter.CustomViewHolder holder, int position) {
holder.txtTitle.setText(dataList.get(position).getComment());
holder.txttime.setText(dataList.get(position).getUpdated_at());
holder.userNametitle.setText(dataList.get(position).getuser_name());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(view.getContext(), "" + dataList.get(position).getId(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return dataList.size();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google提供了一个用于该目的的库,即
paging
库,您可以知道它的工作原理概述“ rel =” nofollow noreferrer”>在此处从Google文档中,您可以关注此Google provides a library for that purpose which is
paging
library, you can know how it works here from google documentation, or you can follow this video where you will learn how to use paging library to achieve the result that you want.第一件事函数
生成的atatalist
必须仅首次致电因此,我将从
onCreat
中调用它,您可以这样创建您的布局:
我们将为
nestedscrollview
设置滚动侦听器,然后我们将更改
showdata()
:First thing the function
generateDataList
must call first time onlySo I'm going to call it from the
onCreat
You can create your layout like this:
And we going to set the scroll listener for
NestedScrollView
And We going to change
showData()
: