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

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

 更新時間:2016年03月03日 11:21:49   投稿:mrr  
在android程序開發(fā)中,無論是單選按鈕還是多選按鈕都非常的常見,接下來通過本文給大家介紹Android程序開發(fā)中單選按鈕(RadioGroup)的使用,需要的朋友參考下吧

在還沒給大家介紹單選按鈕(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程序開發(fā)中單選按鈕(RadioGroup)的使用詳解,希望對大家有所幫助!

相關文章

最新評論

巴彦淖尔市| 新昌县| 黄梅县| 罗田县| 固始县| 巨鹿县| 抚松县| 新河县| 靖边县| 常山县| 深圳市| 马尔康县| 宾阳县| 南安市| 涪陵区| 夏津县| 泰兴市| 金湖县| 康平县| 阜宁县| 曲沃县| 新宾| 新巴尔虎左旗| 沿河| 延庆县| 喀喇沁旗| 泰州市| 大石桥市| 库尔勒市| 浙江省| 漳平市| 托克逊县| 黔西| 东乌| 华阴市| 河北省| 崇州市| 丰台区| 泽库县| 梁山县| 忻城县|