Core-Adapter
Support Any Type of items in recyclerview with no pain
add to project:
compile 'ir.coderz.coreadapter:Core-Adapter:0.1.9@aar'
Usage:
0. ViewHolders are normal:
public class TextHolder extends RecyclerView.ViewHolder {
private TextView textView;
public TextHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.text);
}
public TextView getTextView() {
return textView;
}
}
CoreItem<YOUR_VIEW_HOLDER,YOUR_DATA_MODEL>
1. Items must implement public class TextItem implements CoreItem<TextHolder, String> {
@Override
public void bind(TextHolder textHolder) {
// This is the onbind method used to be inside adapter
textHolder.getTextView().setText(textHolder.getAdapterPosition() + "");
}
@Override
public int getLayout() {
// You must return the related layout
return R.layout.text_item;
}
@Override
public String getData() {
// you might need the data! so return it here :)
return textHolder.getAdapterPosition() + "";
}
}
CoreAdapter
for Recyclerviews adapter
2. Use CoreAdapter coreAdapter = new CoreAdapter();
recycler.setAdapter(coreAdapter);
3. what layout for what viewholder?
coreAdapter.putViewType(R.layout.YOUR_LAYOUT, YOUR_HOLDER.class);
4. Fill the adapter by core items:
coreAdapter.addItem(new TextItem());