Android RadioButton使用

Android RadioButton使用,第1张

概述例题2-12activity_main.xml代码1<?xmlversion="1.0"encoding="utf-8"?>2<GridLayoutandroid:layout_width="fill_parent"3android:layout_height="fill_parent"4android:columnCount="4"5

例题2-12

activity_main.xml代码

 1 <?xml version="1.0" enCoding="utf-8"?> 2 <GrIDLayout androID:layout_wIDth="fill_parent" 3     androID:layout_height="fill_parent" 4     androID:columnCount="4" 5     androID:rowCount="6" 6     xmlns:androID="http://schemas.androID.com/apk/res/androID"> 7     <RadioGroup> 8         <Radiobutton androID:ID="@+ID/boy" 9             androID:layout_wIDth="wrap_content"10             androID:layout_height="wrap_content"11             androID:checked="true"12             androID:text="男"/>13         <Radiobutton androID:ID="@+ID/girl"14             androID:layout_wIDth="wrap_content"15             androID:layout_height="wrap_content"16             androID:text="女"/>17     </RadioGroup>18     <button androID:ID="@+ID/but1"19         androID:layout_wIDth="wrap_content"20         androID:layout_height="wrap_content"21         androID:text="确认"22         androID:layout_columnSpan="4"/>23     <TextVIEw androID:ID="@+ID/text1"24         androID:layout_height="wrap_content"25         androID:layout_wIDth="wrap_content"26         androID:text="" />27 </GrIDLayout>

mainactivity.java代码

 1 package com.example.hello; 2  3 import androIDx.appcompat.app.AppCompatActivity; 4  5 import androID.os.Bundle; 6 import androID.telephony.SmsManager; 7 import androID.vIEw.VIEw; 8 import androID.Widget.button; 9 import androID.Widget.CheckBox;10 import androID.Widget.Progressbar;11 import androID.Widget.Radiobutton;12 import androID.Widget.TextVIEw;13 14 public class MainActivity extends AppCompatActivity {15     button but1;16     TextVIEw textVIEw;17     Radiobutton radiobutton1,radiobutton2;18     @OverrIDe19     protected voID onCreate(Bundle savedInstanceState) {20         super.onCreate(savedInstanceState);21         setContentVIEw(R.layout.activity_main);22         textVIEw = (TextVIEw)findVIEwByID(R.ID.text1);23         but1 = (button)findVIEwByID(R.ID.but1);24         radiobutton1 = (Radiobutton)findVIEwByID(R.ID.boy);25         radiobutton2 = (Radiobutton)findVIEwByID(R.ID.girl);26         but1.setonClickListener(new VIEw.OnClickListener() {27             @OverrIDe28             public voID onClick(VIEw v) {29                 String s="";30                 if(radiobutton1.isChecked())31                     s=s+radiobutton1.getText();32                 if (radiobutton2.isChecked())33                     s=s+radiobutton2.getText();34                 textVIEw.setText("性别:"+s);35             }36         });37 38     }39 40 }

 

总结

以上是内存溢出为你收集整理的Android RadioButton使用全部内容,希望文章能够帮你解决Android RadioButton使用所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1060147.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存