XML Version
XML Version
andika_project3
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.CompoundButton
import android.widget.RadioButton
import android.widget.Toast
import com.example.andika_project3.databinding.ActivityMainBinding
binding.ne.setOnCheckedChangeListener(this)
binding.es.setOnCheckedChangeListener(this)
binding.btnPilih.setOnClickListener(View.OnClickListener {
val buttonId: Int =
binding.radioGroupPeminatan.checkedRadioButtonId
if (buttonId == View.NO_ID) {
Toast.makeText(this@MainActivity, "Nothing selected",
Toast.LENGTH_SHORT).show()
} else {
val selectedRadioButton =
findViewById<RadioButton>(buttonId)
Toast.makeText(this@MainActivity,selectedRadioButton.text,
Toast.LENGTH_SHORT).show()
}
})
}
override fun onCheckedChanged(compoundButton: CompoundButton,
isChecked: Boolean) {
// if (compoundButton is RadioButton && isChecked) {
//
Toast.makeText(this@MainActivity,compoundButton.getText().toString() ,Toast
.LENGTH_SHORT).show()
// }
}
fun onRadioButtonClicked(view: View) {}
}
2.
3
<resources>
<string name="app_name">Andika_Project3</string>
<string name="radio_NE">Network Engineering</string>
<string name="radio_ES">Embedded Systems</string>
<string name="radio_SF">Software</string>
<string name="radio_IOT">IOT</string>
<string name="pilih">Pilih Peminatan</string>
</resources>