Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Can I add multiple binder with same DataModel? #100

Closed
kawtikwar opened this issue Aug 29, 2019 · 2 comments
Closed

Can I add multiple binder with same DataModel? #100

kawtikwar opened this issue Aug 29, 2019 · 2 comments

Comments

@kawtikwar
Copy link

I want to add multiple binders with the same DataModel as shown below

Binder1 class

public class Binder1 extends ItemBinder<DataModel, Binder1.ViewHolder> {

    @Override
    public Binder1 createViewHolder(ViewGroup parent) {
        return new ViewHolder(inflate(parent,R.layout.list_item));
    }

    @Override
    public void bindViewHolder(ViewHolder holder, DataModel dataModel) {
       
    }

    @Override
    public boolean canBindData(Object item) {
        return item instanceof DataModel;
    }

    static class ViewHolder extends ItemViewHolder<DataModel> {
        
        public NotificationViewHolder(View itemView) {
            super(itemView);
          
        }
    }
}

Binder2 class

public class Binder2 extends ItemBinder<DataModel, Binder2.ViewHolder> {

    @Override
    public Binder2 createViewHolder(ViewGroup parent) {
        return new ViewHolder(inflate(parent,R.layout.list_item_one));
    }

    @Override
    public void bindViewHolder(ViewHolder holder, DataModel dataModel) {
       
    }

    @Override
    public boolean canBindData(Object item) {
        return item instanceof DataModel;
    }

    static class ViewHolder extends ItemViewHolder<DataModel> {
        
        public NotificationViewHolder(View itemView) {
            super(itemView);
          
        }
    }
}
 MultiViewAdapter adapter = new MultiViewAdapter();
        
            recyclerView.setAdapter(adapter);

            // Register Binder
            adapter.registerItemBinders(new Binder1(), new Binder2());

            // Create Section and add items
            ListSection<DataModel> listSection = new ListSection<>();
  List<DataModel> list = new ArrayList<>();
  list.add(new DataModel());
  list.add(new DataModel());
  listSection.addAll(list);

            // Add Section to the adapter
            adapter.addSection(listSection);

Can I do like the above?
If not then how to achieve this using MultiViewAdapter.

I have the same model class but need to show different View Type on the basis of some parameter̥

@kawtikwar kawtikwar added the new Describes the issue is reported recently and not reviewed by the maintainers label Aug 29, 2019
@DevAhamed DevAhamed added type:question and removed new Describes the issue is reported recently and not reviewed by the maintainers labels Aug 29, 2019
@DevAhamed
Copy link
Owner

Yes, you can do that.

For example, inside Binder1,

    @Override
    public boolean canBindData(Object item) {
        return item instanceof DataModel && ((DataModel) item).getSomeParameter().equals(MY_VALUE_HERE);
    }

Similarly you can do that for other binders as well.

@kawtikwar
Copy link
Author

Thank You @DevAhamed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants