在 Kotlin Fragments 中将数据从一个 RadioGroup 传递到另一个

问题描述

全新的 Kotlin 并且没有 Java 经验,我需要将数据从一个片段中的 radioGroup 传递到另一个片段:

我有 2 个单独的片段,在 片段 1 - 创建片段 中,用户从 radioGroup (addCategoryType) 中选择一个单选按钮 - 以及在各种 editText 字段中输入数据 - 并显示这些值在用户点击保存后的 cardView 中(也保存到 Firebase 数据库) 当用户点击 cardView 中的卡片时,它会打开片段 2 - 编辑片段用户可以在其中编辑他们在片段 1 中输入的详细信息

一切正常,只是我不知道如何将之前选择的单选按钮设置为当前选择的 editCategoryType

创建片段:

        val categoryIs = if (addCategoryType.checkedRadioButtonId == R.id.ArtCategory) "Art / Workshop"
        else
            if (addCategoryType.checkedRadioButtonId == R.id.MusicCategory) "Music / Live Performances"
            else
                if (addCategoryType.checkedRadioButtonId == R.id.socialCategory) "Social / Networking"
                else
                    if (addCategoryType.checkedRadioButtonId == R.id.CharityCategory) "Charity / Fundraising"
                    else
                        if (addCategoryType.checkedRadioButtonId == R.id.BusinessCategory) "Business / Technology"
                        else
                            if (addCategoryType.checkedRadioButtonId == R.id.FoodCategory) "Food / Trade Shows"
                            else "No Category Selected"

        writeNewEvent(
                EventModel(
                        categorytype = categoryIs,time = timeTV.text.toString(),date = dateTV.text.toString(),eventTitle = eventTitle.text.toString(),eventDetails = eventDescription.text.toString(),

编辑片段

  root.editCategoryType.setText(editEvents!!.categorytype)

    root.editEventTitle.setText(editEvents!!.eventTitle)
    root.editEventDetails.setText(editEvents!!.eventDetails)
    root.editTime.setText(editEvents!!.time)
    root.editDate.setText(editEvents!!.date)

但显然 setText 在这里不起作用。

然后点击保存以保存所做的任何编辑

    editEvents!!.categorytype = root.editCategoryType.toString()

    editEvents!!.eventTitle = root.editEventTitle.text.toString()
    editEvents!!.eventDetails = root.editEventDetails.text.toString()
    editEvents!!.time = root.editTime.text.toString()
    editEvents!!.date = root.editDate.text.toString()

标题、详细信息、日期和时间都按预期工作,有人能帮我解决代码中的 categoryType 数据吗?

提前致谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...