最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android程序開(kāi)發(fā)中單選按鈕(RadioGroup)的使用詳解

 更新時(shí)間:2016年03月03日 11:21:49   投稿:mrr  
在android程序開(kāi)發(fā)中,無(wú)論是單選按鈕還是多選按鈕都非常的常見(jiàn),接下來(lái)通過(guò)本文給大家介紹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)文章

最新評(píng)論

格尔木市| 乐至县| 赣榆县| 仪陇县| 公主岭市| 阿巴嘎旗| 阳曲县| 迁西县| 蓬莱市| 兴安盟| 永年县| 苏尼特左旗| 安丘市| 峨山| 林西县| 陆丰市| 老河口市| 罗城| 民乐县| 滨海县| 广灵县| 光山县| 灵山县| 德钦县| 临沧市| 柘城县| 黎平县| 新营市| 静乐县| 沅陵县| 碌曲县| 志丹县| 比如县| 北海市| 鹤山市| 博乐市| 怀化市| 沈阳市| 永登县| 江陵县| 大庆市|