ahmedrizwan / RxRecyclerAdapter

Rx based RecyclerView Adapter
192 stars 28 forks source link

Only showing one element #13

Closed dagostinelli closed 6 years ago

dagostinelli commented 6 years ago

I'm trying to use the lib and my list view is only displaying the first element.

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.simple_recyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

RxDataSource<SimpleViewModel> rxDataSource = new RxDataSource<>(generateSimpleList());

rxDataSource
    .<MyLayoutBinding>bindRecyclerView(recyclerView, R.layout.my_layout)
    .subscribe(viewHolder -> {
        MyLayoutBinding b = viewHolder.getViewDataBinding();
        SimpleViewModel x = viewHolder.getItem();
        b.simpleTextView.setText(x);
    });

The list is of 100 elements

    private List<SimpleViewModel> generateSimpleList() {
        List<SimpleViewModel> simpleViewModelList = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            simpleViewModelList.add(new SimpleViewModel(String.format(Locale.US, "This is item %d", i)));
        }

        return simpleViewModelList;
    }

SimpleViewModel

public class SimpleViewModel {
    private String simpleText;

    public SimpleViewModel(@NonNull final String simpleText) {
        Check.requireNonNull(simpleText);
        setSimpleText(simpleText);
    }

    @NonNull
    public String getSimpleText() {
        return simpleText;
    }

    public void setSimpleText(@NonNull final String simpleText) {
        Check.requireNonNull(simpleText);
        this.simpleText = simpleText;
    }
}
dagostinelli commented 6 years ago

This was the solution. It had nothing to do with this lib.