2017-08-04 8 views
2

最初に複数のRadioButtonをあらかじめ選択しておくと、Android APIレベル24(エミュレータ)で複数の選択ができるようです。私はこれがバグかどうかを知りたいだけですか?ここでAndroid RadiGroupで複数の選択が可能

は、レイアウトファイルです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RadioGroup 
     android:id="@+id/radioGroup" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/metal" 
      android:checked="true"/> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/classical" 
      android:checked="true"/> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/jazz"/> 

    </RadioGroup> 

</LinearLayout> 

アプリは、次のように起動します:

enter image description here

そして、私はジャズをクリックした場合、それはこのようになった:

enter image description here

+0

おそらくバグではなく、XMLで2つをチェックしたが、単一選択肢を設定しなかったので説明します。そのため、ユーザーが選択肢を1つだけ選択してラジオグループの単一選択をしたい場合は、 –

+0

'android:id'の値を' RadioButton'ウィジェットに割り当ててみてください。 [この問題](https://issuetracker.google.com/issues/36910867)を参照してください。 – CommonsWare

+0

@CommonsWare、ありがとう、idを割り当てることはトリックを行い、最後にチェックされたものがUIでチェックされます。 Btw私はあなたの本を勉強していた:) –

答えて

2

あなたのレイアウトには01がありませんRadioButtonウィジェットの値はです。これは、レイアウトリソースであらかじめチェックされているもので始まっていないのであれば、動作します。レイアウトリソースでandroid:checkedを使用する場合は、RadioButtonウィジェットにウィジェットIDを割り当てる必要があります。これはa long-standing issueだから、変更する必要はありません。そのため、Androidアプリ開発で対処しなければならない "それは単なるものの1つ"です。

関連する問題