title: The best practice to make radio buttons respond to onClick events pragramatically within fragment (kotlin)
body: <p>I`m looking for the best practice to make radio buttons respond to onClick events pragramatically within fragment (kotlin).</p>
  <p>I came up with this solution, but i dont think that this is the best one. Here is a little snippet:</p>
  <pre><code>override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
  
      fun onRadioButtonClicked(view: View) {
          if (view is RadioButton) {
              val checked = view.isChecked
  
              when (view.getId()) {
                  R.id.option1 -&gt;
                      if(checked) {
                          do something
                      }
                  R.id.option2 -&gt;
                      if(checked) {
                          do something
                      }
                  R.id.option3 -&gt;
                      if(checked) {
                          do something
                      }
                  R.id.option4 -&gt;
                      if(checked) {
                          do something
                      }
                  R.id.option5 -&gt;
                      if(checked) {
                          do something
                      }
              }
          }
      }
  
  itemOptions = arrayOf(
          binding.option1,
          binding.option2,
          binding.option3,
          binding.option4,
          binding.option5
      )
  
  itemOptions.forEach { x -&gt;
          x.setOnClickListener{onRadioButtonClicked(x)}
      }
  </code></pre>
  <p>Can anyone suggest a better alternative?</p>