3
3
import android .content .Context ;
4
4
import android .graphics .Color ;
5
5
import android .os .SystemClock ;
6
- import android .util .Log ;
7
6
import android .view .LayoutInflater ;
8
7
import android .widget .RadioButton ;
9
8
import android .widget .RadioGroup ;
@@ -38,28 +37,28 @@ protected AndroidSegmented createViewInstance(ThemedReactContext reactContext) {
38
37
}
39
38
40
39
41
- private int position ;
42
-
43
40
@ Override
44
41
protected void addEventEmitters (final ThemedReactContext reactContext , final AndroidSegmented view ) {
45
42
46
43
view .setOnCheckedChangeListener (new RadioGroup .OnCheckedChangeListener () {
47
44
@ Override
48
45
public void onCheckedChanged (RadioGroup group , int checkedId ) {
46
+
49
47
int childCount = view .getChildCount ();
50
- for (int i =0 ;i <childCount ;i ++){
51
- if (view .getChildAt (i ).getId ()==checkedId ){
52
- position = i ;
48
+ for (int i = 0 ; i < childCount ; i ++) {
49
+ ((RadioButton )view .getChildAt (i )).setChecked (false );
50
+ if (view .getChildAt (i ).getId () == checkedId ) {
51
+ ((RadioButton )view .getChildAt (i )).setChecked (true );
52
+
53
+
54
+ reactContext .getNativeModule (UIManagerModule .class ).getEventDispatcher ()
55
+ .dispatchEvent (
56
+ new AndroidSegmentedEvent (
57
+ view .getId (),
58
+ SystemClock .uptimeMillis (),
59
+ i ));
53
60
}
54
61
}
55
- reactContext .getNativeModule (UIManagerModule .class ).getEventDispatcher ()
56
- .dispatchEvent (
57
- new AndroidSegmentedEvent (
58
- view .getId (),
59
- SystemClock .uptimeMillis (),
60
- position ));
61
-
62
-
63
62
}
64
63
});
65
64
@@ -70,21 +69,21 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
70
69
@ ReactProp (name = "childText" )
71
70
public void setChildText (AndroidSegmented view , ReadableArray data ) {
72
71
int childCount = data .size ();
73
- Log .e ("TAG" , "___" + childCount );
74
72
75
- for (int i = 0 ; i < childCount ; i ++ ) {
73
+ for (int i = 0 ; i < childCount ; ++ i ) {
76
74
RadioButton child = (RadioButton ) LayoutInflater .from (context ).inflate (R .layout .radio_button , null );
77
75
78
76
child .setText (data .getString (i ));
79
77
view .addView (child );
80
78
79
+
81
80
}
82
81
}
83
82
84
83
85
84
@ ReactProp (name = "selectedPosition" )
86
85
public void setSelectedChild (AndroidSegmented view , int position ) {
87
- RadioButton radioBt = (RadioButton )(view .getChildAt (position ));
86
+ RadioButton radioBt = (RadioButton ) (view .getChildAt (position ));
88
87
radioBt .setChecked (true );
89
88
}
90
89
0 commit comments