-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getText() always return empty string from dynamically created Chip component #394
Comments
Hi it seems the text will be in the ChipDrawable. Does chip.getChipDrawable().getText() work? Seems like a bug though, filed this one: |
Hi, thanks for the response. Yes it works when getting the text from the ChipDrawable instead. Just to make it more clear, it is |
Hi @Kenc44 are programmatically creating a ChipDrawable and setting it on a chip in order to programmatically specify the chip style? Have you tried creating a theme overlay that can be passed into the chip constructor? |
Hi @wcshi I only create a |
This should fix your issue: |
Yes that fixed the issue. Thanks. |
I'm trying to dynamically create some choice chip components based on an ArrayList of String from some computation and following are the code to create the chips and adding them to a ChipGroup created in layout XML file.
The Chips displayed correctly with the text but when I tried to call getText() on the chips, it always return empty String but not the text contained by the chips. I tested this by setting the OnCheckedChangeListener on the ChipGroup and making a Toast with the text (though it didn;'t work). When I tried to display only the checkedId it works.
My current workaround is to have a variable holding the array results and use
ArrayList.get(selectedChipId.getTitle())
. but don't think it should be that way thoughI also found that it is able to get text from Chips added in layout file but not run-time added Chips. Tried with both 1.1.0/alpha06 and 1.1.0/alpha07 release but am having no luck. Would like to have some advice if possible. Thank you very much.
The text was updated successfully, but these errors were encountered: