我从tmdb api获取数据。 我正在尝试将API的结果传递给我的DetailActivity。
创建界面,适配器,模型和模型结果后。 我调用了getReviews,但每次都得到相同的错误:非静态方法getReviewResult()不能从静态上下文中引用。
当我将它设置为静态时,我的整个代码都会出错。
Bellow是我的模特课ReviewResult。 公共课ReviewResult {
private List<Reviews> reviewResults;
public List<Reviews> getReviewResults() {
return reviewResults;
}}
并且错误的DetailActivity类:rAdapter.setReviewList(ReviewResult.getReviewResults());
public class MovieDetailActivity extends AppCompatActivity {
public static final String EXTRA_MOVIE = "EXTRA_MOVIE";
private Movie mMovie;
private Reviews mReviews;
private Genres mGenres;
public ReviewAdapter rAdapter;
private RecyclerView rRecyclerView;
//private MoviesAdapter.ReviewAdapter rAdapter;
ImageView backdrop;
ImageView poster;
TextView title;
TextView description;
TextView releaseDate;
TextView voteAverage;
ListView reviews;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_detail);
if (getIntent().hasExtra(EXTRA_MOVIE)) {
mMovie = getIntent().getParcelableExtra(EXTRA_MOVIE);
} else {
throw new IllegalArgumentException("Detail activity must receive a movie parcelable");
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
toolbarLayout.setTitle(mMovie.getTitle());
//ucitavanje adaptera
//rRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
//rRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
rAdapter = new ReviewAdapter(MovieDetailActivity.this);
rRecyclerView.setAdapter(rAdapter);
backdrop = (ImageView) findViewById(R.id.backdrop);
title = (TextView) findViewById(R.id.movie_title);
description = (TextView) findViewById(R.id.movie_description);
releaseDate = (TextView) findViewById(R.id.movie_date);
voteAverage = (TextView) findViewById(R.id.movie_rating);
//genres = (ListView) findViewById(R.id.genresArray);
reviews = (ListView) findViewById(R.id.reviewList);
title.setText(mMovie.getTitle());
description.setText(mMovie.getDescription());
voteAverage.setText(mMovie.getVoteAverage());
releaseDate.setText(mMovie.getReleaseDate());
poster = (ImageView) findViewById(R.id.movie_poster);
String internetUrl = "http://image.tmdb.org/t/p/w500";
Glide.with(this)
.load(mMovie.getPoster())
.override(800, 890)
.into(poster);
Glide.with(this)
.load(mMovie.getBackdrop())
.into(backdrop);
}
private void getReviews() {
RestAdapter.getMovieService().getReviews(new Callback<ReviewResult>() {
@Override
public void success(ReviewResult reviewResult, Response response) {
rAdapter.setReviewList(ReviewResult.getReviewResults());
}
@Override
public void failure(RetrofitError error) {
error.printStackTrace();
}
});
}
public static class MovieViewHolder extends RecyclerView.ViewHolder {
public ImageView imageView;
public MovieViewHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.picture_review);
}
}
}