關於RadioButton在RadioGroup默認選中的問題

在RadioGroup中添加了幾個RadioButton,然後設置其中某一個默認是選中狀態的時候,
裏面的每一個RadioButton都需要設置一個id,不然會出現都可選中的情況
錯誤的寫法:

<RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|bottom"
            android:orientation="horizontal">
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="http"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="rtsp"/>
        </RadioGroup>

正確的寫法:

<RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|bottom"
            android:orientation="horizontal">
            <RadioButton
                android:id="@+id/radio_http"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="http"/>
            <RadioButton
                android:id="@+id/radio_rtsp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="rtsp"/>
        </RadioGroup>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章