MaterialChipsInput icon indicating copy to clipboard operation
MaterialChipsInput copied to clipboard

Is there a way to limit number of selected chips

Open Hazem-Ben-Khalfallah opened this issue 7 years ago • 2 comments

something like setMaxSelectedChips(int maxNumber)

Hazem-Ben-Khalfallah avatar May 11 '17 13:05 Hazem-Ben-Khalfallah

For now, there is no feature like that. But it's a nice idea for future release !

pchmn avatar May 18 '17 08:05 pchmn

@Hazem-Ben-Khalfallah

if you want it to limit only for 1 which is recently selected then you can do it like

Customise ChipsInput.java add

public boolean isShowMultipleChip() 
{
 return mShowMultipleChip;
//to show single or multiple chips return boolean 
}

  public void setShowMultipleChip(boolean mShowMultipleChip) {
        this.mShowMultipleChip = mShowMultipleChip;
    }

In onCreate() set ChipsInput behaviour by calling

mChipsInput.setShowMultipleChip(//true or false);

update addChip(ChipInterface chip) { } to

public void addChip(ChipInterface chip) {

     if(isShowMultipleChip()){
         mChipsAdapter.addChip(chip);

     }else {
         mChipsAdapter = new ChipsAdapter(mContext, this, mRecyclerView);
         mRecyclerView.setAdapter(mChipsAdapter);

         mChipsAdapter.addChip(chip);
     }

   }

androleaven avatar Jul 28 '17 11:07 androleaven