0

I am building an app where Observable emitts ArrayList, and that list has 2 items, but when I run the app on screen it is shown more than once(I see this 2 items, but they are shown more than once). What am I doing wrong? This is my code:

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());

                        }
                    });
        }
    });
Goran_1992
  • 103
  • 1
  • 2
  • 9
  • I see this 2 items, but they are shown more than once - what do you mean by this line? – Nongthonbam Tonthoi Jun 08 '16 at 12:27
  • Well. this list has 2 items only,and it has to emmit just this 2 items and that's it, it should be the end, but in my case, that list repeats again and again, and as a result of that, i have many items on the screen..I hope that you understand me... – Goran_1992 Jun 08 '16 at 12:32
  • Just clear the adapter before setting the list items – Nongthonbam Tonthoi Jun 08 '16 at 12:36
  • Could you write me that part of code, please? – Goran_1992 Jun 08 '16 at 12:38
  • Just try something like this yourAdapter.clear(); – Nongthonbam Tonthoi Jun 08 '16 at 12:40
  • Thanks mate, it works! But now I have another problem. If I have an ArrayList of 20 items, and I want on first page to show first 10 items, and on second another 10 items, and with this Adapter.clear I am deleting first 10 when go on page 2, but i Want to all 20 items be there, I dont want to that first 10 items be deleted.On the top of my code this "page" in getIdeas(page) represents number of page...I hope that you understand me... – Goran_1992 Jun 08 '16 at 13:28

0 Answers0