markzhai / DataBindingAdapter

Super simple RecyclerView adapter using Data Binding Technology.
Apache License 2.0
243 stars 34 forks source link

add MultiViewTyper interface for random data get viewType #1

Closed coofee closed 8 years ago

coofee commented 8 years ago

添加 MultiViewTyper接口,方便从不确定顺序的数据中获取viewType。

    final List<Object> data = new ArrayList<Object>();
        data.addAll(EMPLOYEE_LIST);
        data.addAll(EMPLOYER_LIST);
        Collections.shuffle(data);
        mMultiTypeAdapter.addAll(data, new MultiTypeAdapter.MultiViewTyper() {
            @Override
            public int getViewType(Object item) {
                if (item instanceof EmployerViewModel) {
                    return VIEW_TYPE_EMPLOYER;
                }

                if (item instanceof EmployeeViewModel) {
                    return VIEW_TYPE_EMPLOYEE;
                }

                return 0;
            }
        });