我正在构建一个Observable发出ArrayList的应用程序,该列表有2个项目,但是当我在屏幕上运行应用程序时,它会被多次显示(我看到这两个项目,但它们不止一次显示)。我究竟做错了什么? 这是我的代码:
ideaService.getIdeas(page)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ArrayList<Item>>() {
@Override
public void onCompleted() {
if (ideaAdapter.getItemCount() > 0) {
ideaAdapter.notifyDataSetChanged();
//ideaAdapter.setLoaded();
// startingText.setVisibility(View.GONE);
//mRecycleView.setVisibility(View.VISIBLE);
}
else {
startingText.setText(getString(R.string.no_ideas));
}
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}
ideaAdapter.setLoaded();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
dialog.show();
}
@Override
public void onNext(ArrayList<Item> items) {
//Remove loading item
//ideaAdapter.getmItems().remove(ideaAdapter.getmItems().size() - 1);
//ideaAdapter.notifyItemRemoved(ideaAdapter.getmItems().size());
ideaAdapter.setList(items);
Log.d("Array", "arrayListONE " + ideaAdapter.getmItems().size());
}
});
}
});