如何在选择不同的单选按钮时更改提示?

时间:2016-11-05 09:40:05

标签: android radio-button

我创建了3个单选按钮。有2个edittext字段和一个下拉列表。会有提示,但也可以编辑文本和下拉菜单。默认情况下,应显示第一个按钮的提示。现在,下拉列表位于两个文本字段之间。在选择第二个按钮时,我希望提示更改,下拉列表应位于两个edittexts之上。我该怎么做?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e5e5e5">


<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_weight="0.90"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <RadioButton android:id="@+id/radio_recharge"
        android:layout_width="wrap_content"
        android:text="Mobile"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:onClick="onRadioButtonClicked"/>

    <RadioButton android:id="@+id/radio_bills"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
        android:layout_width="wrap_content"
        android:text="DTH"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:onClick="onRadioButtonClicked"/>

    <RadioButton android:id="@+id/radio_transfer"
        android:layout_width="wrap_content"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
        android:text="DataCard"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:onClick="onRadioButtonClicked"/>


</RadioGroup>

<LinearLayout
    android:orientation="vertical"
    android:layout_weight="0.10"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:layout_marginTop="5dp"
        android:text="Mobile Number"
        android:ems="10"
        android:id="@+id/editText2" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_marginTop="10dp"
        android:layout_height="wrap_content"
        android:background="@android:drawable/btn_dropdown"
        android:spinnerMode="dropdown" />



    <EditText
        android:layout_width="match_parent"
        android:layout_marginTop="10dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="Recharge Amount"
        android:ems="10"
        android:id="@+id/editText" />
</LinearLayout>

1 个答案:

答案 0 :(得分:1)

要设置提示以编辑文本,您可以使用setHint(&#34;提示文字&#34;)方法。

您可以在微调器和底部编辑文本之间再创建一个编辑文本,并将可见性设置为已消失。 在选中的第二个单选按钮上,使可见性最高的编辑文本消失,并使微调器和底部编辑文本之间的编辑文本可见