Android RadioButton單選框的使用方法
public class MainActivity extends Activity {
public RadioGroup mRadioGroup1;
public RadioButton mRadio1, mRadio2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRadioGroup1 = (RadioGroup) findViewById(R.id.gendergroup);
mRadio1 = (RadioButton) findViewById(R.id.girl);
mRadio2 = (RadioButton) findViewById(R.id.boy);
mRadioGroup1.setOnCheckedChangeListener(radiogpchange);
}
private RadioGroup.OnCheckedChangeListener radiogpchange = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == mRadio1.getId()) {
Toast.makeText(getApplicationContext(), "女孩", 1).show();
} else if (checkedId == mRadio2.getId()) {
Toast.makeText(getApplicationContext(), "男孩", 1).show();
}
}
};
}
RadioButton:就像是C#中的Radio控件,可以為控件設(shè)置Group,每個Group中的項只能選擇一項;
<RadioGroup
android:id="@+id/gendergroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/girl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/girl" />
<RadioButton
android:id="@+id/boy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/boy" />
</RadioGroup>
- Android單選按鈕RadioButton的使用詳解
- Android控件RadioButton實現(xiàn)多選一功能
- Android開發(fā)設(shè)置RadioButton點擊效果的方法
- Android編程實現(xiàn)自定義PopupMenu樣式示例【顯示圖標(biāo)與設(shè)置RadioButton圖標(biāo)】
- Android RadioButton 圖片位置與大小實例詳解
- Android RadioGroup和RadioButton控件簡單用法示例
- Android中設(shè)置RadioButton在文字右邊的方法實例
- android RadioButton和CheckBox組件的使用方法
- Android定制RadioButton樣式三種實現(xiàn)方法
- Android控件系列之RadioButton與RadioGroup使用方法
- Android控件RadioButton的使用方法
相關(guān)文章
Android混合開發(fā)教程之WebView的使用方法總結(jié)
WebView是一個基于webkit引擎、展現(xiàn)web頁面的控件,下面這篇文章主要給大家介紹了關(guān)于Android混合開發(fā)教程之WebView的使用方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧2018-05-05android開發(fā)環(huán)境中SDK文件夾下的所需內(nèi)容詳解
在本篇文章里小編給大家整理的是關(guān)于android開發(fā)環(huán)境中SDK文件夾下的所需內(nèi)容詳解,有興趣的朋友們參考學(xué)習(xí)下。2019-09-09解決android studio卡頓,提升studio運行速度的方法
這篇文章主要介紹了解決android studio卡頓,提升studio運行速度的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03利用Kotlin的協(xié)程實現(xiàn)簡單的異步加載詳解
這篇文章主要給大家介紹了關(guān)于利用Kotlin的協(xié)程實現(xiàn)簡單的異步加載的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03Android中一個應(yīng)用實現(xiàn)多個圖標(biāo)的幾種方式
這篇文章主要給大家介紹了在Android中一個應(yīng)用如何實現(xiàn)多個圖標(biāo)的幾種方式,其中包括了多Activity + intent-filter方式、activity-alias方式以及網(wǎng)頁標(biāo)簽-添加快捷方式,分別給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒。2017-05-05