我正在通过原生Android实现一个数据请求表单,用户应该在其中输入各种字段.请考虑以下场景:

  1. 其中一个字段要求Insurance?,它需要Yes/No个输入.
  2. 如果前一字段的输入是Yes,那么它应该要求输入Insurance Number.
Label Input
Insurance? (TextView) * Yes * No (RadioGroup)

如果前一个输入是Yes,那么我们应该会收到下一个请求,如下所示:

Label Input
Insurance Number (TextView) ......................... (EditView)

有没有人能帮我理解一下,我该如何实现这一点? 已try 搜索此查询,但未找到.如果这个问题是重复的,请告诉我.

推荐答案

在这里,当用户在"保险?"中 Select "是"时.字段中,"保险号码"字段变为可见,而当他们 Select "否"时,该字段变为隐藏状态.

 RadioGroup radioGroupInsurance =findViewById(R.id.radioGroupInsurance);
  TextView textViewInsuranceNumber = findViewById(R.id.textViewInsuranceNumber);
 EditText editTextInsuranceNumber =findViewById(R.id.editTextInsuranceNumber);

radioGroupInsurance.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    if (checkedId == R.id.radioYes) {
        textViewInsuranceNumber.setVisibility(View.VISIBLE);
        editTextInsuranceNumber.setVisibility(View.VISIBLE);
    } else if (checkedId == R.id.radioNo) {
        textViewInsuranceNumber.setVisibility(View.GONE);
        editTextInsuranceNumber.setVisibility(View.GONE);
    }
}

});

Android相关问答推荐

如何自定义所选的NavigationBar项目?

如何使TextField的背景透明?

长流与长流的比较<>

Android库中的kotlinCompilerExtensionVersion

如何更新Kotlin中的显示?

StateFlow和LazyColumn重组

无法加载类';com.android.build.api.extension.AndroidComponentsExtension';

在Jetpack Compose中实现焦点突出的最佳方式?

如何在使用 PointerInput 修改器时添加点击时的波纹效果

通过 setIntentScanningStrategyEnabled(true) 未检测到信标的 Android Beacon 库后台扫描

Material 3 中的 ModalBottomSheet 用于 compose

修复错误 Invariant Violation: requireNativeComponent: "RNSScreenStackHeaderConfig" was not found in the UIManager

Jetpack Compose 部分或开放侧边框

在事件中使用 Context/Toast 时不需要的重组 - Jetpack Compose

在事件中使用 Context/Toast 时不需要的重组 - Jetpack Compose

LazyColumn 单选中的状态提升. Jetpack compose

我的观点在jetpack compose中相互重叠

Material Design 网站的新设计已启动,但我找不到实现选项卡,该选项卡在哪里?

Jetpack Compose Material3 - switch 标签

如何在 kotlin 的 android room DB 中设置一对多关系