RadioGroup with two columns which have ten RadioButtons

后端 未结 12 1953
难免孤独
难免孤独 2020-11-27 07:16

I have a RadioGroup and I want to align buttons next to each other in two columns and five rows and I am unable to achieve it. Things I have tried:

12条回答
  •  醉梦人生
    2020-11-27 07:33

    this solution for handle click inside click body

    xml :

                 
    
                            
    
                                
    
                                
    
    
                                
                            
    
                            
    
                                
    
                                
    
                                
    
                            
                        
    

    code :

     private var isChecking = true
    
     mBinding.radioGroupAction1.setOnCheckedChangeListener { radioGroup, i ->
            if (i != -1 && isChecking) {
                isChecking = false
                mBinding.radioGroupAction2.clearCheck()
            }
            isChecking = true
            when (i) {
                R.id.a -> {
                   Log.e("radioGroupAction:", "a")
                }
                R.id.b -> {
                   Log.e("radioGroupAction:", "b")
                }
                R.id.c -> {
                   Log.e("radioGroupAction:", "c")
                }
            }
        }
        mBinding.radioGroupAction2.setOnCheckedChangeListener { radioGroup, i ->
            if (i != -1 && isChecking) {
                isChecking = false
                mBinding.radioGroupAction1.clearCheck()
            }
            isChecking = true
            when (i) {
                R.id.d -> {
                   Log.e("radioGroupAction:", "d")
                }
                R.id.e -> {
                   Log.e("radioGroupAction:", "e")
                }
                R.id.f -> {
                   Log.e("radioGroupAction:", "f")
                }
            }
        }
    

    Good Luck

提交回复
热议问题