Good afternoon, I need to display the item by the user-entered id. Do I need to change something in the request or onResponse () method?
Request:
public interface RequestInterface { @GET("/posts/{n}") Call <List<Post>> getData(@Query("n") int n); } Answer:
requestInterface.getData(3).enqueue(new Callback<List<Post>>() { @Override public void onResponse(Call<List<Post>> call, Response<List<Post>> response) { posts.addAll(response.body()); recyclerView.getAdapter().notifyDataSetChanged(); } Post.java:
public class Post { @SerializedName("userId") @Expose private int userId; @SerializedName("id") @Expose private int id; @SerializedName("title") @Expose private String title; @SerializedName("body") @Expose private String body; public int getUserId() { return userId; } public void setUserId(int userId) { this.userId = userId; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getBody() { return body; } public void setBody(String body) { this.body = body; }