【发布时间】:2018-11-30 06:11:52
【问题描述】:
我试图使用 Retrofit 2 将 JSON 数据提取到 RecyclerView 中。我还实现了分页。现在进行测试,我更改了 JSON URL,就好像它只会在每页显示 5items。可以通过在 JSON URL 末尾添加“&page=PAGE#”来更改页码(其中 PAGE# 是从 1 开始的整数值,如果没有提及页码,则默认显示第一页)。
问题:我已成功地将每个页面添加到 Recyclerview。但是,它会将最后一页的项目添加两次,有时会添加 3 次。
像这样:
最后一个帖子会加几次
我找不到问题所在。一步一步的调试没有帮助。请帮我。我正在学习这些,如果你能帮助我,我将不胜感激。
WPPOST POJO:
public class WPPost {
@SerializedName("code")
@Expose
private String code;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("guid")
@Expose
private Guid guid;
@SerializedName("title")
@Expose
private Title title;
@SerializedName("content")
@Expose
private Content content;
@SerializedName("post_categories")
@Expose
private List < String > postCategories = null;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Guid getGuid() {
return guid;
}
public void setGuid(Guid guid) {
this.guid = guid;
}
public Title getTitle() {
return title;
}
public void setTitle(Title title) {
this.title = title;
}
public Content getContent() {
return content;
}
public void setContent(Content content) {
this.content = content;
}
public List < String > getPostCategories() {
return postCategories;
}
public void setPostCategories(List < String > postCategories) {
this.postCategories = postCategories;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
模型类:
public class Model {
public int postid;
public String title;
public String content;
public String categoriesnames;
public Model(int mID, String mTitle, String mContent, String mCategorynames) {
this.postid = mID;
this.title = mTitle;
this.content = mContent;
this.categoriesnames = mCategorynames;
}
}
【问题讨论】:
-
你检查过服务器的回复吗?
-
是的。我已经检查了回复。没关系。没有重复的响应。
标签: java android android-recyclerview retrofit2