Bonjour,
dans mon application, je souhaite utiliser 4 Radiogroup (contenant chacun 2 Radiobutton), lorsqu'un Radiobutton est sélectionné tous les autres doivent être déselectionnés (même ceux appartenant à un autre radiogroup). L'extrait du layout contenant ces Radiogroup est le suivant:
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
 
        <RadioGroup
            android:id="@+id/estate_type_radio_group_1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:checkedButton="@+id/filter_estate_type_a"
            android:orientation="horizontal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/sleeping_room_range_seek_bar">
 
            <RadioButton
                android:id="@+id/filter_estate_type_h"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/house_with_state_48"
                android:drawableLeft="@drawable/house_with_state_48"
                android:text="@string/house" />
 
            <RadioButton
                android:id="@+id/filter_estate_type_a"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/apartment_with_state_48"
                android:drawableLeft="@drawable/apartment_with_state_48"
                android:text="@string/apartment" />
 
        </RadioGroup>
 
        <RadioGroup
            android:id="@+id/estate_type_radio_group_2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:orientation="horizontal"
 
            app:layout_constraintEnd_toEndOf="@+id/estate_type_radio_group_1"
            app:layout_constraintStart_toStartOf="@+id/estate_type_radio_group_1"
            app:layout_constraintTop_toBottomOf="@+id/estate_type_radio_group_1"
            >
 
            <RadioButton
                android:id="@+id/filter_estate_type_s"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/studio_with_state_48"
                android:drawableLeft="@drawable/studio_with_state_48"
                android:text="@string/studio" />
 
            <RadioButton
                android:id="@+id/filter_estate_type_r"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/sleeping_room_with_state_48"
                android:drawableLeft="@drawable/sleeping_room_with_state_48"
                android:text="@string/sleeping_room" />
 
        </RadioGroup>
 
 
        <RadioGroup
            android:id="@+id/estate_type_radio_group_3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:orientation="horizontal"
 
            app:layout_constraintEnd_toEndOf="@+id/estate_type_radio_group_2"
            app:layout_constraintStart_toStartOf="@+id/estate_type_radio_group_2"
            app:layout_constraintTop_toBottomOf="@+id/estate_type_radio_group_2">
 
            <RadioButton
                android:id="@+id/filter_estate_type_local_c"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/local_commel_with_state_48"
                android:drawableLeft="@drawable/local_commel_with_state_48"
                android:text="@string/local_commercial" />
 
            <RadioButton
                android:id="@+id/filter_estate_type_apps"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/appartement_with_state_48"
                android:drawableLeft="@drawable/appartement_with_state_48"
                android:text="Appartements meubles"/>
 
        </RadioGroup>
        <RadioGroup
            android:id="@+id/estate_type_radio_group_4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@+id/estate_type_radio_group_3"
            app:layout_constraintStart_toStartOf="@+id/estate_type_radio_group_3"
            app:layout_constraintTop_toBottomOf="@+id/estate_type_radio_group_3"
            >
 
            <RadioButton
                android:id="@+id/filter_estate_ty"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:drawableStart="@drawable/ter_with_state_48"
                android:drawableLeft="@drawable/ter_with_state_48"
                android:text="Terrain" />
 
            <RadioButton
                android:id="@+id/filter_estate_type_roo"
                style="@style/EstateTypeRadioButtonStyle"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="8dp"
                android:layout_weight="1"
                android:visibility="invisible"
                android:drawableStart="@drawable/sleeng_rm_with_state_48"
                android:drawableLeft="@drawable/sleeng_rm_with_state_48"
                android:text="@string/sleeping_room" />
 
        </RadioGroup>
 
 
           </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Le code java associé est le suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
isChecking = true;
mEstateTypeGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                if (checkedId != -1 && isChecking) {
                    isChecking = false;
                    mEstateTypeGroup2.clearCheck();
                    mEstateTypeGroup3.clearCheck();
                    mEstateTypeGroup4.clearCheck();
                    mEstateTypeCheckedId = checkedId;
                }
                isChecking = true;
            }
        });
        mEstateTypeGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                if (checkedId != -1 && isChecking) {
                    isChecking = false;
                    mEstateTypeGroup1.clearCheck();
                    mEstateTypeGroup3.clearCheck();
                    mEstateTypeGroup4.clearCheck();
                    mEstateTypeCheckedId = checkedId;
                }
                isChecking = true;
            }
        });
 
        mEstateTypeGroup3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                if (checkedId != -1 && isChecking) {
                    isChecking = false;
                    mEstateTypeGroup1.clearCheck();
                    mEstateTypeGroup2.clearCheck();
                    mEstateTypeGroup4.clearCheck();
                    mEstateTypeCheckedId = checkedId;
                 }
                isChecking = true;
            }
        });
 
        mEstateTypeGroup4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                if (checkedId != -1 && isChecking) {
                    isChecking = false;
                    mEstateTypeGroup1.clearCheck();
                    mEstateTypeGroup2.clearCheck();
                    mEstateTypeGroup3.clearCheck();
                    mEstateTypeCheckedId = checkedId;
                    }
 
                isChecking = true;
            }
        });
Lorsque j'execute mon app,je constate que lorsqu'un Radiobutton est selectionné si je souhaite en sélectionner un autre d'un autre Radiogroup, je dois appuyer sur le RadioButton au moins 2 fois avant qu'il ne soit sélectionné.

Svp, aurez vous une idée sur la façon de procéder de manière correcte?
Je souhaiterais autant que possible garder la solution avec plusieurs RadioGroup.
Par avance, merci