单击单选组Android Studio中的单选按钮后启用EditText

单击单选组Android Studio中的单选按钮后启用EditText,android,Android,我有一个RadioGroup,里面有6个单选按钮。如果用户单击第6个单选按钮,EditText将启用键入。否则,编辑文本将保持禁用状态。我在这个网站上尝试了很多解决方案,但仍然有一些错误。最常见的错误是EditText保持禁用,尽管我在单击第6个单选按钮时将其设置为启用。以下是XML的代码: <TableRow android:layout_width="match_parent" android:layout_height="wrap_c

我有一个RadioGroup,里面有6个单选按钮。如果用户单击第6个单选按钮,EditText将启用键入。否则,编辑文本将保持禁用状态。我在这个网站上尝试了很多解决方案,但仍然有一些错误。最常见的错误是EditText保持禁用,尽管我在单击第6个单选按钮时将其设置为启用。以下是XML的代码:

 <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="25dp">

            <RadioGroup
                android:id="@+id/rgSuggestWill"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/colorAccent"
                android:textStyle="bold"
                android:checkedButton="@+id/rbSaveCost">

                <RadioButton
                    android:id="@+id/rbSaveCost"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:checked="false"
                    android:focusable="auto"
                    android:text="Save Cost"
                    android:textSize="18sp"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"/>

                <RadioButton
                    android:id="@+id/rbRevenue"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:checked="false"
                    android:focusable="auto"
                    android:text="Increase Revenue"
                    android:textSize="18sp"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"/>

                <RadioButton
                    android:id="@+id/rbQuality"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:checked="false"
                    android:focusable="auto"
                    android:text="Improve Quality"
                    android:textSize="18sp"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"/>

                <RadioButton
                    android:id="@+id/rbWorkProcess"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:checked="false"
                    android:focusable="auto"
                    android:text="Improve Work Process Efficiency"
                    android:textSize="18sp"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"/>

                <RadioButton
                    android:id="@+id/rbSafety"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:checked="false"
                    android:focusable="auto"
                    android:text="Improve Safety"
                    android:textSize="18sp"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"/>

                <RadioButton
                    android:id="@+id/rbOwnValue"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:checked="false"
                    android:focusable="auto"
                    android:text="Specify your own value: "
                    android:textSize="18sp"
                    android:textColor="@color/colorAccent"
                    android:textStyle="bold"/>
            </RadioGroup>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="25dp">

            <EditText
                android:id="@+id/etOwnValue"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:padding="10dp"
                android:textColor="@color/colorAccent"
                android:textStyle="bold"
                android:background="@layout/rounded_border_edittext"
                android:ems="10"
                android:hint="Others" />
        </TableRow>
这可能会帮助您:

// getting the groug
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup);  

    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // checkedId is the RadioButton selected
if(checkedId==6) {
// if the id of the checkedId equels to the id of the 6 button than make the editText enable 

myEditText.setEnable(true)
} else {
// else (wich mean that other redio button been clicked) make it disable.
myEditText.setEnable(false)
}
        }
    });

在xml中,决定您的声明状态启用或禁用

您还需要发布一些相关的代码。这样我们才能更好地理解这个问题。请不要发布整个代码,这将造成混乱。感谢您的贡献。这似乎是成功的。当我单击第六个RB时,编辑文本将启用,I更改为第五个RB,编辑文本保持启用状态。嗨,检查您获得的id