The recent project has used multiple lines of RadioButton, as recorded.
Give the layout of the RadioButton first
<com.kuibu.jucai.widget.myradiogroup
Android:id= "@+id/myradiogroup"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content" >
<radiobutton
Android:id= "@+id/rb_50"
Android:layout_width= "Match_parent"
android:layout_height= "35DP"
android:layout_marginleft= "@dimen/space_10"
android:layout_weight= "1"
android:background= "@drawable/poundage_selector"
android:button= "@null"
android:gravity= "Center"
android:paddingbottom= "@dimen/space_10"
android:paddingleft= "@dimen/space_20"
android:paddingright= "@dimen/space_20"
android:paddingtop= "@dimen/space_10"
android:text= "50¥"
Android:textcolor= "@drawable/fg_order_text_selector"/>
<radiobutton
Android:id= "@+id/rb_100"
Android:layout_width= "Match_parent"
android:layout_height= "35DP"
android:layout_marginleft= "@dimen/space_10"
android:layout_weight= "1"
android:background= "@drawable/poundage_selector"
android:button= "@null"
android:gravity= "Center"
android:paddingbottom= "@dimen/space_10"
android:paddingleft= "@dimen/space_20"
android:paddingright= "@dimen/space_20"
android:paddingtop= "@dimen/space_10"
android:text= "100¥"
Android:textcolor= "@drawable/fg_order_text_selector"/>
<radiobutton
Android:id= "@+id/rb_150"
Android:layout_width= "Match_parent"
android:layout_height= "35DP"
android:layout_marginleft= "@dimen/space_10"
android:layout_marginright= "@dimen/space_10"
android:layout_weight= "1"
android:background= "@drawable/poundage_selector"
android:button= "@null"
android:gravity= "Center"
android:paddingbottom= "@dimen/space_10"
android:paddingleft= "@dimen/space_30"
android:paddingright= "@dimen/space_30"
android:paddingtop= "@dimen/space_10"
android:text= "150¥"
Android:textcolor= "@drawable/fg_order_text_selector"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content" >
<radiobutton
Android:id= "@+id/rb_200"
Android:layout_width= "Match_parent"
android:layout_height= "35DP"
android:layout_marginleft= "@dimen/space_10"
android:layout_margintop= "@dimen/space_10"
android:layout_weight= "1"
android:background= "@drawable/poundage_selector"
android:button= "@null"
android:gravity= "Center"
android:paddingbottom= "@dimen/space_10"
android:paddingleft= "@dimen/space_20"
android:paddingright= "@dimen/space_20"
android:paddingtop= "@dimen/space_10"
android:text= "200¥"
Android:textcolor= "@drawable/fg_order_text_selector"/>
<radiobutton
Android:id= "@+id/rb_500"
Android:layout_width= "Match_parent"
android:layout_height= "35DP"
android:layout_marginleft= "@dimen/space_10"
android:layout_margintop= "@dimen/space_10"
android:layout_torightof= "@+id/rb_200"
android:layout_weight= "1"
android:background= "@drawable/poundage_selector"
android:button= "@null"
android:gravity= "Center"
android:paddingbottom= "@dimen/space_10"
android:paddingleft= "@dimen/space_20"
android:paddingright= "@dimen/space_20"
android:paddingtop= "@dimen/space_10"
android:text= "500¥"
Android:textcolor= "@drawable/fg_order_text_selector"/>
<radiobutton
Android:id= "@+id/rb_1000"
Android:layout_width= "Match_parent"
android:layout_height= "35DP"
android:layout_marginleft= "@dimen/space_10"
android:layout_marginright= "@dimen/space_10"
android:layout_margintop= "@dimen/space_10"
android:layout_torightof= "@+id/rb_500"
android:layout_weight= "1"
android:background= "@drawable/poundage_selector"
android:button= "@null"
android:gravity= "Center"
android:paddingbottom= "@dimen/space_10"
android:paddingleft= "@dimen/space_20"
android:paddingright= "@dimen/space_20"
android:paddingtop= "@dimen/space_10"
android:text= "1000¥"
Android:textcolor= "@drawable/fg_order_text_selector"/>
</LinearLayout>
</com.kuibu.jucai.widget.MyRadioGroup>
A custom control is used here, as follows
public class Myradiogroup extends Radiogroup {
External Storm leaks
Private Oncheckedchangelistener Moncheckedchangelistener;
Public Myradiogroup (Context context) {
Super (context);
}
Public Myradiogroup (context context, AttributeSet Attrs) {
Super (context, attrs);
}
public void Setoncheckedchangelistener (Oncheckedchangelistener listener) {
Moncheckedchangelistener = listener;
}
@Override
public void AddView (final View child, int index, viewgroup.layoutparams params) {
if (child instanceof LinearLayout) {
int childCount = ((linearlayout) child). Getchildcount ();
for (int i = 0; i < ChildCount; i++) {
View view = ((linearlayout) child). Getchildat (i);
if (view instanceof RadioButton) {
Final RadioButton button = (RadioButton) view;
((RadioButton) button). Setontouchlistener (New Ontouchlistener () {
@Override
public boolean OnTouch (View V, motionevent event) {
((RadioButton) button). Setchecked (True);
Checkradiobutton ((RadioButton) button);
if (Moncheckedchangelistener! = null) {
Moncheckedchangelistener.oncheckedchanged (Myradiogroup.this, Button.getid ());
}
return true;
}
});
}
}
}
Super.addview (Child, index, params);
}
private void Checkradiobutton (RadioButton RadioButton) {
View child;
int radiocount = Getchildcount ();
for (int i = 0; i < Radiocount; i++) {
Child = Getchildat (i);
if (child instanceof RadioButton) {
if (child = = RadioButton) {
Do nothing
} else {
((RadioButton) child). Setchecked (false);
}
} else if (child instanceof LinearLayout) {
int childCount = ((linearlayout) child). Getchildcount ();
for (int j = 0; J < ChildCount; J + +) {
View view = ((linearlayout) child). Getchildat (j);
if (view instanceof RadioButton) {
Final RadioButton button = (RadioButton) view;
if (Button = = RadioButton) {
Do nothing
} else {
((RadioButton) button). setchecked (false);
}
}
}
}
}
}
}
The network is not good, can not directly insert code, only such a copy.
The use of Android multi-line RadioButton