我有一个RecyclerView设置,应该显示一个电影列表。问题是我在进行API调用后得到了数据。所以我的问题是:如何在我的Activity的onCreate方法之后设置数据?
// Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movie_overview, container, false);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
movieOverviewPresenter.loadMovies();
return rootView;
}
@Override
public void showMovie(List<Movie> movies) {
mAdapter = new MovieOverviewAdapter(movies);
mRecyclerView.setAdapter(mAdapter);
}
// Presenter
@Override
public void loadMovies() {
retrofit.create(MovieService.class).getPopularMovies("API_KEY").subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.unsubscribeOn(Schedulers.io())
.subscribe(new Observer<Result>() {
@Override
public void onCompleted() {
Log.i("Request", "Success!");
}
@Override
public void onError(Throwable e) {
Log.d("Request", "Error: " + e);
}
@Override
public void onNext(Result result) {
mView.showMovie(result.getResults());
}
});
}
&#13;
答案 0 :(得分:0)
在onResume()中调用showMovie()。
答案 1 :(得分:0)
您必须通过在onComplete()
回调中调用Group Value
A 15
A 5
B 4
B 2
C 25
C 15
告诉适配器数据已在一段时间后更新。