Android程序开发中单选按钮(RadioGroup)的使用详解

Android程序开发中单选按钮(RadioGroup)的使用详解,第1张

概述在还没给大家介绍单选按钮(RadioGroup)的使用,先给大家展示下效果图吧:xml文件

在还没给大家介绍单选按钮(RadioGroup)的使用,先给大家展示下效果图吧:


xml文件

<linearLayoutxmlns: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 classMainActivity extends Activity { private TextVIEw txt=null; private RadioGroup sex=null; private Radiobutton male=null; private Radiobutton female=null; @OverrIDe protected voIDonCreate(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(newOnCheckedchangelistenerImp()); } private classOnCheckedchangelistenerImp implementsOnCheckedchangelistener{ public voIDonCheckedChanged(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)的使用详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1149610.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存