android custom radio button not getting checked

后端 未结 2 1927
长发绾君心
长发绾君心 2020-12-07 06:26

I have created radio group with custom layout i.e. custom button.




        
相关标签:
2条回答
  • 2020-12-07 06:34

    Its the android:button="@null", please remove it from the xml file completely. Try using this simple xml layout.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    
        <RadioGroup
            android:id="@+id/radio_group_rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  >
    
            <RadioButton
                android:id="@+id/radio_platinum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="platinum" />
    
            <RadioButton
                android:id="@+id/radio_gold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="gold" />
    
            <RadioButton
                android:id="@+id/radio_silver"
               android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="silver" />
            </RadioGroup>
    
        <Button
            android:id="@+id/btn_submit"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="submit" />
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-07 06:34

    Only difference to my code is that I don't put clickable="true" in xml, if RadioGroup handles touch event by itself to manage child radio buttons you should remove that attribute as clickable is generally set to true automatically when you set an OnClickListener.

    0 讨论(0)
提交回复
热议问题