王中义,球形摄像机,网络赚钱教程
在还没给大家介绍单选按钮(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程序开发中单选按钮(radiogroup)的使用详解,希望对大家有所帮助!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio 解决logcat无过滤工具栏的操作
Android Studio 恢复小窗口停靠模式(Docked Mode)
Android studio保存logcat日志到本地的操作
Android Studio快捷键生成TAG、Log.x日志输出介绍
网友评论