Android程序開(kāi)發(fā)中單選按鈕(RadioGroup)的使用詳解
在還沒(méi)給大家介紹單選按鈕(RadioGroup)的使用,先給大家展示下效果圖吧:
xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <TextView android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="您的性別為"/> <RadioGroup android:id="@+id/sex" android:layout_width="fill_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/male" android:text="男"/> <RadioButton android:id="@+id/female" android:text="女"/> </RadioGroup> </LinearLayout>
java文件
public class MainActivity extends Activity { private TextView txt=null; private RadioGroup sex=null; private RadioButton male=null; private RadioButton female=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.txt=(TextView) super.findViewById(R.id.txt); this.sex=(RadioGroup) super.findViewById(R.id.sex); this.male=(RadioButton) super.findViewById(R.id.male); this.female=(RadioButton) super.findViewById(R.id.female); this.sex.setOnCheckedChangeListener(new OnCheckedChangeListenerImp()); } private class OnCheckedChangeListenerImp implements OnCheckedChangeListener{ public void onCheckedChanged(RadioGroup group, int checkedId) { String temp=null; if(MainActivity.this.male.getId()==checkedId){ temp="男"; } else if(MainActivity.this.female.getId()==checkedId){ temp="女"; } MainActivity.this.txt.setText("您的性別是"+temp); } }
以上所述是小編給大家介紹的Android程序開(kāi)發(fā)中單選按鈕(RadioGroup)的使用詳解,希望對(duì)大家有所幫助!
相關(guān)文章
android中強(qiáng)制更新app實(shí)例代碼
本篇文章主要介紹了android中強(qiáng)制更新app實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05Kotlin中的對(duì)象表達(dá)式和對(duì)象聲明的具體使用
這篇文章主要介紹了Kotlin中的對(duì)象表達(dá)式和對(duì)象聲明的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11Android實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06詳解Android Material Design自定義動(dòng)畫(huà)的編寫(xiě)
這篇文章主要介紹了詳解Android Material Design自定義動(dòng)畫(huà)的編寫(xiě),其中對(duì)Activity的過(guò)渡動(dòng)畫(huà)進(jìn)行了重點(diǎn)講解,需要的朋友可以參考下2016-04-04Ubuntu16.04 LTS 下安裝 Android Studio 2.2.2 的詳細(xì)步驟
這篇文章主要介紹了Ubuntu16.04 LTS 下安裝 Android Studio 2.2.2 的詳細(xì)步驟,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11Android中DownloadManager實(shí)現(xiàn)文件下載實(shí)例詳解
這篇文章主要介紹了Android中DownloadManager實(shí)現(xiàn)文件下載實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-03-03Handler制作簡(jiǎn)單相冊(cè)查看器的實(shí)例代碼
下面小編就為大家分享一篇Handler制作簡(jiǎn)單相冊(cè)查看器的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01android ListView的右邊滾動(dòng)滑塊啟用方法 分享
android ListView的右邊滾動(dòng)滑塊啟用方法 分享,需要的朋友可以參考一下2013-05-05Android 中HttpURLConnection與HttpClient使用的簡(jiǎn)單實(shí)例
這篇文章介紹了Android 中HttpURLConnection與HttpClient使用的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-10-10