High-imitation express delivery 100-RadioGroup and RadioButton applications in practice, 100-radiogroup
1. Differences between RadioButton and CheckBox:
A. After a single RadioButton is selected, it cannot be changed to unselected by clicking
After a single CheckBox is selected, it can be changed to unselected by clicking
B. A group of RadioButton can only be selected at the same time.
A group of checkpoints that can be selected at the same time
C. RadioButton is represented in a circle by default in most UI frameworks.
In most UI frameworks, CheckBox is represented by a rectangle by default.
2. Relationship between RadioButton and RadioGroup:
A. RadioButton indicates a Single Circular Single-circle, while RadioGroup is a container that can hold multiple RadioButton.
B. Only one RadioButton in each RadioGroup can be selected at the same time.
C. RadioButton in different radiogroups is irrelevant. That is, if one of group A is selected, one of group B can still be selected.
D. In most cases, a RadioGroup contains at least two RadioButton
E. In most cases, RadioButton in a RadioGroup will be selected by default. We recommend that you place it in the starting position of the RadioGroup.
3. After a brief introduction, let's take a look at this application:
A simple pop-up pop is provided, and the four order statuses are provided, which is not difficult to implement. Let's take a look at the xml code:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/rl_order_parent" android:orientation="vertical" > <RelativeLayout android:id="@id/top_arrow" android:layout_width="fill_parent" android:layout_height="@dimen/height_title_bar" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:src="@drawable/btn_sort_arrow" /> </RelativeLayout> <RadioGroup android:id="@+id/btn_sort" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/top_arrow" android:background="@drawable/btn_sort_bg" android:checkedButton="@id/btn_sort_unsigned" android:gravity="center" android:orientation="horizontal" android:padding="10.0dip" > <RadioButton android:id="@+id/btn_sort_all" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:background="#00000000" android:button="@null" android:clickable="true" android:drawableTop="@drawable/btn_sort_all_selector" android:gravity="center" android:scaleType="matrix" android:text="@string/btn_sort_all" android:textColor="@color/grey_878787" /> <RadioButton android:id="@+id/btn_sort_unsigned" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:background="#00000000" android:button="@null" android:clickable="true" android:drawableTop="@drawable/btn_sort_unsigned_selector" android:gravity="center" android:scaleType="matrix" android:text="@string/btn_sort_unsigned" android:textColor="@color/blue_kuaidi100" /> <RadioButton android:id="@+id/btn_sort_signed" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:background="#00000000" android:button="@null" android:clickable="true" android:drawableTop="@drawable/btn_sort_signed_selector" android:gravity="center" android:scaleType="matrix" android:text="@string/btn_sort_signed" android:textColor="@color/grey_878787" /> <RadioButton android:id="@+id/btn_sort_recycle" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:background="#00000000" android:button="@null" android:clickable="true" android:drawableTop="@drawable/btn_sort_recycle_selector" android:gravity="center" android:scaleType="matrix" android:text="@string/btn_sort_recycle" android:textColor="@color/grey_878787" /> </RadioGroup> <View android:id="@+id/btn_grey_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/btn_sort" android:background="@color/black_7000" /></RelativeLayout>
From the xml layout file, we can see that radiogroup is used and contains four radiobutton. In this way, the pop-up popUpWindow can be implemented. in addition, the status selector is used in the RadioButton image to display three different color-worthy images in the selected and normal statuses, respectively. Take one as an example:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/btn_sort_signed_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/btn_sort_signed_selected" android:state_checked="true"/> <item android:drawable="@drawable/btn_sort_signed_normal"/></selector>
Java code:
/*** Display the pop of the Acceptance status */private void showOrderStatusPop () {if (orderStatusPopView = null) {orderStatusPopView = View. inflate (mContext, R. layout. pop_bill_sort, null);} initOrderStatusPopView (); setCurrentCheckedItem (); values (); if (orderStatusPopupWindow = null) {orderStatusPopupWindow = new PopupWindow. FILL_PARENT, LayoutParams. FILL_PARENT); // disable orderStatusPopupWindow clustering. setFocusable (false); // you can specify whether orderStatusPopupWindow can be deleted when you click it. setOutsideTouchable (true); // click "Back" to make it disappear without affecting your background orderStatusPopupWindow. setBackgroundDrawable (new BitmapDrawable ();} int I = DensityUtil. dip2px (mContext, 601_f); iv_arrow.setImageResource (R. drawable. arrow_up_float); orderStatusPopupWindow. showAsDropDown (top, 0,-I);}/*** initialize the order status control */private void initOrderStatusPopView () {rl_order_parent = (RelativeLayout) orderStatusPopView. findViewById (R. id. rl_order_parent); btn_sort = (RadioGroup) orderStatusPopView. findViewById (R. id. btn_sort); btn_sort_all = (RadioButton) orderStatusPopView. findViewById (R. id. btn_sort_all); btn_sort_unsigned = (RadioButton) orderStatusPopView. findViewById (R. id. btn_sort_unsigned); btn_sort_signed = (RadioButton) orderStatusPopView. findViewById (R. id. btn_sort_signed); btn_sort_recycle = (RadioButton) orderStatusPopView. findViewById (R. id. btn_sort_recycle);}/*** listener for setting order status */private void setOrderStatusPopViewListener () {rl_order_parent.setOnClickListener (this); listener (this ); listener (this); // set the listener for the selected changes for the radioGroup to check which listener is selected, so that btn_sort.setOnCheckedChangeListener (new OnCheckedChangeListener () is displayed again next time () {@ Overridepublic void onCheckedChanged (RadioGroup group, int checkedId) {switch (checkedId) {case R. id. btn_sort_all: currentCheckedId = checkedId; break; case R. id. btn_sort_unsigned: currentCheckedId = checkedId; break; case R. id. btn_sort_signed: currentCheckedId = checkedId; break; case R. id. btn_sort_recycle: currentCheckedId = checkedId; break ;}}); btn_sort.check (currentCheckedId);}/*** set the current status */private void setCurrentCheckedItem () {switch (currentCheckedId) {case R. id. btn_sort_all: resetTextColor (); btn_sort_all.setTextColor (mContext. getResources (). getColor (R. color. blue_kuaidi100); break; case R. id. btn_sort_unsigned: resetTextColor (); btn_sort_unsigned.setTextColor (mContext. getResources (). getColor (R. color. blue_kuaidi100); break; case R. id. btn_sort_signed: resetTextColor (); btn_sort_signed.setTextColor (mContext. getResources (). getColor (R. color. blue_kuaidi100); break; case R. id. btn_sort_recycle: resetTextColor (); btn_sort_recycle.setTextColor (mContext. getResources (). getColor (R. color. blue_kuaidi100); break;}/*** reset text color */private void resetTextColor () {btn_sort_all.setTextColor (mContext. getResources (). getColor (R. color. grey_878787); btn_sort_unsigned.setTextColor (mContext. getResources (). getColor (R. color. grey_878787); btn_sort_signed.setTextColor (mContext. getResources (). getColor (R. color. grey_878787); btn_sort_recycle.setTextColor (mContext. getResources (). getColor (R. color. grey_878787 ));}
In this way, a pop-up is implemented and a combination of radioGroup radioButton. In fact, in actual applications, there are also a lot of applications using RadioGroup at the bottom, which is similar to that of the following, this is the introduction of this small knowledge point.