感謝您抽出時間提供幫助
我有一個帶有 3 個單選按鈕和一個 FloatingActionButton 的單選組 activity_main.xml

然后,在我的 MainActivity.kt 中,我為該無線電組設定了一個 setOnCheckedChangeListener
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val actionButtonhome: ExtendedFloatingActionButton = findViewById(R.id.actionButton_home)
val bottomNav : BottomNavigationView = findViewById(R.id.bottom_nav_view)
val radio_group: RadioGroup = findViewById(R.id.radio_group)
val radio_0: RadioButton = findViewById(R.id.radio_0)
val radio_1: RadioButton = findViewById(R.id.radio_1)
val radio_2: RadioButton = findViewById(R.id.radio_2)
radio_group.setOnCheckedChangeListener {radio_group, optionId -> run {
when (optionId) {
R.id.radio_0 -> {
<<-- Problem is this line -->>
actionButtonhome.text = radio_0.text
}
R.id.radio_1 -> {
}
R.id.radio_2 -> {
}
else -> {
}
}
}}
我想要的是將按鈕的文本作為單選按鈕文本 “此字串”
但是當我嘗試時 actionButtonhome.text = radio_0.text "_" "this string"
我得到了一個巨大的錯誤并且 符號突出顯示為紅色

uj5u.com熱心網友回復:
替換radio_0.text為radio_0.text.toString()。問題是.text回傳一個 CharSequence 而不是 String 并且你不能將 CharSequences 與 .
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/537162.html
