java– 嵌入了EditText的Android Radio Button Group

java– 嵌入了EditText的Android Radio Button Group,第1张

概述我的问题是我想要一个拥有3个无线电按钮的无线电组,使用下面的方案.三个选择是:1.[]男2.[]女3.[]自定义:(自我描述的身份)但是,问题是我希望用户在EditText中键入他们自己描述的身份以供我检索.因此,以下代码来自我的XML页面,其中一些元素被“####”阻止.<RadioGroupan

我的问题是我想要一个拥有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 fIEldspublic EditText mEdit;public Radiobutton rbutton;public RadioGroup rSexGroup;rSexGroup = (RadioGroup)findVIEwByID(R.ID.male_female_custom_choice);// get selected radio button from RadioGroupint selectedID = rSexGroup.getCheckedRadiobuttonID();// find radio button by returned IDrbutton = (Radiobutton)findVIEwByID(selectedID);// assign gender based on ID of radio buttonif (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所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存