Allow user to select only 3 items in recyclerview

Basically I want user to select only 3 items from a list in recyclerview

My adapter class holder onclicklistener code:

holder.addproduct.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {


        if (ld.isSelected()) {
        } else {


My model class:

public class Product {
    private boolean isSelected = false;

    public Product() {


    public Product(boolean isSelected) {
        this.isSelected = isSelected;

    public boolean isSelected() {
        return isSelected;

    public void setSelected(boolean selected) {
        isSelected = selected;

isSelected is used to get value of selected items in fragment. Any help would be appreciated.

Read more here:

Content Attribution

This content was originally published by user2294087 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: