How do I access the Chipgroup content so I could save it?

▼魔方 西西 提交于 2019-12-11 19:34:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!