大佬教程收集整理的这篇文章主要介绍了Android程序开发中单选按钮(RadioGroup)的使用详解,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在还没给大家介绍单选按钮(RadioGroup)的使用,先给大家展示下效果图吧:
xml文件
<LinearLayout xmlns:android="http://scheR_975_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_975_11845@as.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程序开发中单选按钮(RadioGroup)的使用详解,希望对大家有所帮助!
以上是大佬教程为你收集整理的Android程序开发中单选按钮(RadioGroup)的使用详解全部内容,希望文章能够帮你解决Android程序开发中单选按钮(RadioGroup)的使用详解所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。