现在我正在从tmdb APi获取电影。
我想从他们的终端获得评论。 http://docs.themoviedb.apiary.io/#reference/movies/movieidreviews/get?console=1
现在我正在从Maintrctivity中将Retrofit的电影转到我的recycleview。 我有三个模型类和接口。
我不知道如何为审核列表创建适配器。 在我创建Adapter之后,我需要在我的DetailsActivity中调用它 有人可以帮帮我吗?
我收到错误: public int getItemCount()
这是我的项目github:https://github.com/adnxy/MyMovieApp
这是我的模型类,我不会在这里写getter和setter:
public class Reviews {
@SerializedName("id_review")
private int id;
@SerializedName("author_review")
private String author;
@SerializedName("content_review")
private String content;
@SerializedName("url_review")
private String url;
审查结果模型类如下:
public class ReviewResult {
private List<Reviews> reviewResults;
public List<Reviews> getReviewResults() {
return reviewResults;
}
ReviewWraper没有getter和setter吼叫:
public class ReviewWraper {
@SerializedName("id")
private int id;
@SerializedName("page")
private int page;
@SerializedName("results")
private List<Reviews> results;
Bellow是我的AdapterClass。 这就是我想要做的,但它不起作用。 我收到错误: public int getItemCount()
public class ReviewAdapter {
private List<Reviews> rReviewList;
private LayoutInflater rInflater;
private Context rContext;
public ReviewAdapter(Context context, List<Reviews> rReviewList) {
this.rContext = context;
this.rReviewList = rReviewList;
this.rInflater = LayoutInflater.from(context);
}
public MovieDetailActivity.MovieViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
View view = rInflater.inflate(R.layout.row_review, parent, false);
public void onBindViewHolder(MovieDetailActivity.MovieViewHolder holder, int position) {
Reviews reviews = rReviewList.get(position);
Picasso.with(rContext)
.load(reviews.getUrl())
.resize(342, 0)
.into(holder.imageView);
}
@Override
public int getItemCount() {
return (rReviewList == null) ? 0 : rReviewList.size();
}
public void setReviewList (List<Reviews> reviewsList) {
this.rReviewList = new ArrayList<>();
this.rReviewList.addAll(reviewsList);
notifyDataSetChanged();
}
private void notifyDataSetChanged() {
}
}
答案 0 :(得分:0)
在ReviewAdapter
课程中:
public class ReviewAdapter extends RecyclerView.Adapter<MainActivity.MovieViewHolder> {
private List<Reviews> rReviewList;
private LayoutInflater rInflater;
private Context rContext;
public ReviewAdapter(Context context, List<Reviews> rReviewList) {
this.rReviewList = rReviewList;
this.rContext = context;
this.rInflater = LayoutInflater.from(context);
}
public MainActivity.MovieViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
// create a new view
View view = rInflater.inflate(R.layout.row_review, parent, false);
return new MainActivity.MovieViewHolder(view);
}
@Override
public void onBindViewHolder(MainActivity.MovieViewHolder holder, int position) {
Reviews reviews = rReviewList.get(position);
Picasso.with(rContext)
.load(reviews.getUrl())
.resize(342, 0)
.into(holder.imageView);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Perform click
}
});
}
@Override
public int getItemCount() {
return rReviewList.size();
}
//To update data
public void setReviewList(List<Reviews> reviewsList) {
this.rReviewList = new ArrayList<>();
this.rReviewList.addAll(reviewsList);
notifyDataSetChanged();
}
}