java – 嵌入了EditText的Android Radio Button Group
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 嵌入了EditText的Android Radio Button Group,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2966字,纯文字阅读大概需要5分钟。
内容图文
我的问题是我想要一个拥有3个无线电按钮的无线电组,使用下面的方案.
三个选择是:
1. []男
2. []女
3. []自定义:(自我描述的身份)
但是,问题是我希望用户在EditText中键入他们自己描述的身份以供我检索.
因此,以下代码来自我的XML页面,其中一些元素被“####”阻止.
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="####"
android:id="@+id/male_female_custom_choice"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<RadioButton android:id="@+id/radio_button_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_button_male"
android:checked="true" />
<RadioButton android:id="@+id/radio_button_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_button_female"
android:checked="false" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="####"
android:weightSum="1">
<RadioButton
android:id="@+id/radio_button_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_button_custom"
android:checked="false" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="####"
android:hint="####"
android:focusableInTouchMode="true"
android:gravity="center"
android:layout_weight="1.05"
android:textSize="14sp" />
<TextView
android:layout_width="42dp"
android:layout_height="43dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="####"
android:id="####"
android:singleLine="true"
android:gravity="center"
android:layout_marginLeft="0dp"
android:textColor="#000000" />
</LinearLayout>
</RadioGroup>
如您所见,我尝试使用LinearLayout来隔离自定义选项.
然而,存在意想不到的和不希望的副作用.
1.除了其他2个预定义性别之外,还可以选择自定义选项.
2.无法单独选择自定义选项.
在活动的实际Java文件中,我有以下代码:
// button, radio button, editText, and Spinner fields
public EditText mEdit;
public RadioButton rButton;
public RadioGroup rSexGroup;
rSexGroup = (RadioGroup)findViewById(R.id.male_female_custom_choice);
// get selected radio button from RadioGroup
int selectedId = rSexGroup.getCheckedRadioButtonId();
// find radio button by returned id
rButton = (RadioButton)findViewById(selectedId);
// assign gender based on id of radio button
if (selectedId == 1) {
pat.gender = "male";
}
if (selectedId == 2) {
pat.gender = "female";
}
if (selectedId == 3) {
mEdit = (EditText)findViewById(R.id.####);
pat.gender = (mEdit.getText().toString());
}
由于我对Java有点生疏,我可能会遇到一些非常新的错误.请指教.
再一次,我正在寻找一种方法来获得一组3个RadioButton,每个都在一条线上,最后一个RadioButton与EditText相邻,从中我可以获得所需的信息.
编辑:这是我希望它看起来像的图片:
(http://i68.tinypic.com/ao2oow.png)
不幸的是,我需要10个声望来发布图片.
内容总结
以上是互联网集市为您收集整理的java – 嵌入了EditText的Android Radio Button Group全部内容,希望文章能够帮你解决java – 嵌入了EditText的Android Radio Button Group所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。