Save the users choice using SharedPreferences
and use it to display the data accordingly.
Settings Activity
private var prefs =
this.getSharedPreferences("com.example.android.appname", Context.MODE_PRIVATE)
radioGroup.setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener { group, checkedId ->
val userChoice = when(checkedId){
R.id.radio1 -> "centigrade"
R.id.radio2 -> "fahrenheit"
}
prefs.edit().putString("temparatureMode", userChoice).apply()
})
// assuming you want to display the data in text field
private var prefs =
this.getSharedPreferences("com.example.android.appname", Context.MODE_PRIVATE)
val selectedChoice = prefs.getString("temparatureMode", "centigrade") // assuming centigrade is default mode
val textfield1 = findViewById<TextView>(R.id.textfield1)
textfield1.text = when(selectedChoice){
"centigrade" -> // logic based on centigrade choice
"fahrenheit" -> // logic based on fahrenheit choice
}
check the docs for more info
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…