问题描述
全新的 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 (将#修改为@)