Android获得文本框 单选框 多选框的值
16lz
2021-01-26
菜鸟Android学习01
如何获得文本框 单选框 多选框的值
> 程序代码分别如下所示
@获得文本框的值private EditText emailEdit ; '''在onCreate方法中通过ID获得控键对象''' emailEdit = (EditText)findViewById(R.id.emailEdit); '''使用getText()方法得到控键的值''' str = emailEdit.getText()+"";
@获得单选框的的值'''1-在.xml布局文件中使用RadioGroup控键生成单选框 程序代码如下所示 '''"@+id/sexRadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="4" android:orientation="horizontal" >"@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" **android:checked="true"** android:text="@string/sex01" /> "@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sex02" /> '''2-在.xml布局文件中使用RadioGroup控键生成单选框 程序代码如下所示 ''''''声明一个RadioGroup对象和一个 RadioButton对象''' private RadioGroup sexRadioGroup ; private RadioButton radioButton ; radioButton =(RadioButton)findViewById(sexRadioGroup.getCheckedRadioButtonId()); str = radioButton.getText()+"";
@获得多选框的的值'''1-在.xml布局文件中使用CheckBox控键生成多选框 '''"@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/city01" /> "@+id/CheckBox02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/city02" /> "@+id/CheckBox03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/city03" />'''在.java 文件中声明一个RadioGroup对象和一个 RadioButton对象''' private CheckBox cb ;'''获得多选框的值''' int [] arr = new int[] {R.id.CheckBox01,R.id.CheckBox02,R.id.CheckBox03}; for(int i = 0 ;iif(cb.isChecked()){ str+= cb.getText()+""; } }
更多相关文章
- android按键映射
- Android游戏开发菜鸟之路(三)
- android rom修改小白有福了
- monkeyrunner在Android(安卓)SDK 4.0中无法运行的解决办法
- Ionic 程序打包发布Android版本
- file(内部存储与外部存储)
- android 环境配置和安装, Android系统包说明,基本控件,常用代码,
- PhoneGap开发Android
- Android(安卓)studio登录界面