Is it possible to create Chips programmatically?
mathias21 opened this issue ยท 11 comments
I'm trying to use this library as a permission list picker but I also want to reflect those that are already included. Do you have a way to deal with this functionality?
Thank you!
The docs say it is possible, but nothing there :(
"Manually (programmatically) create chips" under Key Features
@simon-tse-hs any documentation on how to do this?
Hi @bagintz
I would recommend you to move to https://github.com/pchmn/MaterialChipsInput
It is offering the functionality I was looking for.
@bagintz @mathias21 thanks for the comments. I do believe that https://github.com/pchmn/MaterialChipsInput is really good too. At the moment, we haven't put much focus on our nachos library
@mathias21 and @simon-tse-hs Unfortunately, it doesn't truly extend MultiAutoCompleteTextView, which is what I need :(
Hi i think you can just use set text into the NachoTextView to create the chips.
Use a chip terminator to tell where to chipify the text.
tv.addChipTerminator(';', ChipTerminatorHandler.BEHAVIOR_CHIPIFY_ALL)
tv.setText("american; france; italy; japan;")
@alifgiant hey thanks man! , i was facing the same issue and your method worked !
But its taking quite a long time to add a large number of chips :( i tried with 15 chips and my recycler view was visibly slow
@alifgiant Adding chips using setText
works great. However, if there are lots of chips, only one lines worth of chips is shown once the view is loaded. Once the view gains focus, it grows to show all chips. How can I get the view to grow with the programatically added chips? My view has a height of wrap_content
already.
@alifgiant Adding chips using
setText
works great. However, if there are lots of chips, only one lines worth of chips is shown once the view is loaded. Once the view gains focus, it grows to show all chips. How can I get the view to grow with the programatically added chips? My view has a height ofwrap_content
already.
@daviscodesbugs this is kind of hacky, but it works for me to adjust the view height correctly:
nachoTxt.setText(myList)
nachoTxt.minLines = list?.size ?: 1
nachoTxt.post {
nachoTxt.minLines = 1
}
In fact it's possible to add:
Method setTextWithChips(List<ChipInfo>)
does what we want, in this case, sets text with ChipInfo, and even passing Data Object
thru. Only negative effect is, that all previous ones gets removed, but I wrote a function to add these back:
// Add this to your code, where you want to add a chip. `
List<ChipInfo> chipInfos = getBlankChipInfoList(recipients);`
// After this you can add chip Infos and all previous chips will be in array.
public List<ChipInfo> getBlankChipInfoList(NachoTextView textView) {
List<ChipInfo> chipInfos = new ArrayList<>();
for (Chip chip : textView.getAllChips()) {
chipInfos.add(new ChipInfo(chip.getText(), chip.getData()));
}
return chipInfos;
}