问题
I am using Android's ChipGroup to mark tags on a post, but I'm not sure how do I access them to save them to the database when the user clicks "post".
I found one solution that said that you need to iterate through the group's children then the topic was closed, but I can't understand how to do that. Looked at the documentation and didn't see anything helpful.
Is there a go-to method to do that? I can think of an option to add the tags string to another array aside from the chipgroup, and that arra would be used, but if someone removes a chip I'm in a problem because now I don't know which chip that was.
Edit: ok so I am trying to iterate through the children with a simple for loop, but getting a weird issue.
this is my function that is called when the send button is clicked:
questionButton.setOnClickListener {
for (item in questionChipGroup) {
println("check")
}
postQuestion(
questionTitle.text.toString(),
questionDetails.text.toString(),
questionTags.text.toString(),
System.currentTimeMillis().toString()
)
}
But I get a notice on the for loop saying for loop range must have an iterator method.
I've searched it and a few suggestions have come up but none work for me.
The weird thing though, is that I am trying to limit the function with until questionChipGroup.childCount but until is red and I am getting an "unresolved reference" notice for using until. The same thing happens when I try to use indices.
What could be the issue?
来源:https://stackoverflow.com/questions/55095931/how-do-i-access-the-chipgroup-content-so-i-could-save-it