The Android control RadioButton realizes the function of one out of many

The method of RadioButton to realize the function of selecting one from many is as follows

1、 Introduction

2、 RadioButton implementation of one out of many method

1. Put multiple RadioButtons in one radiogroup

2. Take out each RadioButton in the radiogroup

3. Check whether each RadioButton is selected

4. Take out the value in the selected RadioButton

3、 Code example

design sketch:

code:

fry.Activity01

/RadioButtonDemo1/res/layout/activity01.xml

4、 Harvest

1、

android:textColor="#FFFFFF"

Set the color directly with #ffffff

2、

android:layout_ gravity="center_horizontal"

Text centered

3、

RadioButton can select one from more in radiogroup

4、

android:background="@android:color/black"

Set black, the system has its own color

5、

int len = radioGroup1.getChildCount();

Radiogroup gets the number of children

6、

RadioButton radio = (RadioButton) radioGroup1.getChildAt(i);

Radiogroup get children

7、

if (radio.isChecked())

Determine whether the RadioButton is selected

8、

Toast.makeText(Activity01.this,Toast.LENGTH_LONG).show();

toast

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>