单选按钮点击Android Studio
我正在使用一个带有两个单选按钮的单选组,当我选择一个单选按钮时,该按钮应显示为“是” 编辑文本当我点击“无”按钮时,它应该隐藏编辑文本单选按钮点击Android Studio,android,Android,我正在使用一个带有两个单选按钮的单选组,当我选择一个单选按钮时,该按钮应显示为“是” 编辑文本当我点击“无”按钮时,它应该隐藏编辑文本 <RadioGroup android:id="@+id/MTags" android:layout_width="wrap_content" android:layout_hei
<RadioGroup
android:id="@+id/MTags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="0dp"
>
<RadioButton
android:id="@+id/yesRB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YES"
android:checked="true"
android:layout_marginTop="4dp"
android:layout_marginLeft="10dp"
android:textSize="12dp"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NO"
android:checked="false"
android:layout_marginRight="15dp"
android:layout_marginTop="4dp"
android:textSize="12dp"
android:id="@+id/noRB"
/>
</RadioGroup>
<EditText
android:id="@+id/Recdbgs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recd. No. of Bags"
android:textColor="@android:color/black"
android:textColorHint="@color/colorAmber_900"
android:maxWidth="50dp"/>
我有两个单选按钮“是”和“否”,当我单击“是”时,它将显示记录,当单击“否”时,它将隐藏记录
请建议。试试这个->
RadioGroup groupRadio=findViewById(R.id.MTags);
EditText Recdbgs=findViewById(R.id.Recdbgs);
groupRadio.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId==R.id.yesRB)
{
Recdbgs.setVisibility(View.VISIBLE);
}
else if(checkedId==R.id.noRB)
{
Recdbgs.setVisibility(View.INVISIBLE); //or use View.GONE
}
}
});
为此,可以更改EditText可见性属性。在单选按钮的onClick事件中添加这样的代码
yourEditText.setVisibility(View.GONE); //To hide it
yourEditText.setVisibility(View.VISIBLE); //To show it