butterknife viewholder binding code example

Example: butterknife viewholder binding

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private List<DataObject> data;

    public MyAdapter(List<DataObject> data) {
        this.data = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_layout, parent, false);
        return new ViewHolder(view);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.row_header_view) View rowHeaderView;
        @BindView(R.id.row_header_view_text) TextView headerTextView;

        @BindView(R.id.row_data_view) View rowDataView;
        @BindView(R.id.row_data_view_text) TextView rowDataTextView;
        @BindView(R.id.row_data_view_detail_text) TextView rowDataDetailTextView;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}

Tags:

Php Example