Generic RecyclerView adapter
Clone or download
leonid.ustenko Updated items fixed
Latest commit 0be3e9e Jul 28, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
app Updated items fixed Jul 28, 2018
generic-adapter Updated items fixed Jul 28, 2018
gradle/wrapper v1.0.0 Mar 1, 2018
.gitignore Initial commit Aug 24, 2017 Updated items fixed Jul 28, 2018
build.gradle Updated items fixed Jul 28, 2018 Initial commit Aug 24, 2017
gradlew Initial commit Aug 24, 2017
gradlew.bat Initial commit Aug 24, 2017
settings.gradle v1.0.0 Mar 1, 2018

Generic RecyclerView Adapter.

Lightweight library which simplifies creating RecyclerView adapters and illuminates writing boilerplate code.

Creating adapters is as easy as never before, just follow the steps below:

1. Add dependency to your build.gradle (app-level).

dependencies {
    implementation "com.leodroidcoder:generic-adapter:1.0.1"

2. Create a ViewHolder:

public class UserViewHolder extends BaseViewHolder<User, OnRecyclerItemClickListener> {

    private TextView nameTv;

    public UserViewHolder(View itemView, OnRecyclerItemClickListener listener) {
        super(itemView, listener);
        // initialize view and set click listener
        nameTv = itemView.findViewById(;
        if (listener != null) {
                    itemView.setOnClickListener(v -> listener.onItemClick(getAdapterPosition()));

    public void onBind(User item) {
        // bind data to the views

Or in Kotlin:

class UserViewHolder(itemView: View, listener: OnRecyclerItemClickListener?) : BaseViewHolder<User, OnRecyclerItemClickListener>(itemView, listener) {

    private val nameTv: TextView? = itemView.tv_name

    init {
        listener?.run {
            itemView.setOnClickListener { onItemClick(adapterPosition) }

    override fun onBind(item: User) {
        nameTv?.text =

3. Create an Adapter:

public class SimpleAdapter extends GenericRecyclerViewAdapter<User, OnRecyclerItemClickListener, UserViewHolder> {

    public SimpleAdapter(Context context, OnRecyclerItemClickListener listener) {
        super(context, listener);

    public UserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new UserViewHolder(inflate(R.layout.item_user, parent), getListener());

Or in Kotlin:

class SimpleAdapter(context: Context, listener: OnRecyclerItemClickListener) : GenericRecyclerViewAdapter<User, OnRecyclerItemClickListener, UserViewHolder>(context, listener) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
        return UserViewHolder(inflate(R.layout.item_user, parent), listener)

That's it!!

Just use it as a regular adapter in your Fragment or Activity:

public class YourFragment extends Fragment implements OnRecyclerItemClickListener {

    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // ...
        // instantiate the adapter and set it onto a RecyclerView
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), this);

        // populate adapter with data when it is ready
        List<User> users = getYourUsers();

     * This is a callback of the recycler listener.
     * {@link OnRecyclerItemClickListener}.
     * Is being triggered when an item has been clicked.
     * @param position clicked position
    public void onItemClick(int position) {
        // get the User entity, associated with the clicked item.
        final User clickedUser = adapter.getItem(position);
        // do whatever you want with it

Simplifies creating:

  • Regular adapters
  • Adapters with multiple ViewTypes
  • with multiple listeners per item
  • with DiffUtil

Checkout complete samples, including all these use cases.

Or read an article with the detailed explanation: