当前位置: 首页 > 知识库问答 >
问题:

Android-创建Spinner错误消息

柯国安
2023-03-14

所以我在我的应用程序中有一个表单来注册客户端。在这种形式下,我有一个同意下拉菜单,其中有。我想做的是,如果这个人选择no,那么他们就不能完成注册,他们必须选择yes,以便进行下一个活动。对于我的代码,无论用户选择什么,stills都会给出错误消息,并且不允许他们继续前进。

我为此使用的代码是:

数组适配器设置:

//set up for consent spinner
    adapter = ArrayAdapter.createFromResource(this,
            R.array.Register_array_consent, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mspinnerPatientConsent.setAdapter(adapter);

旋转器错误设置:

// Consent Spinner Error set up
    Boolean no_error;
    TextView errorText = (TextView)mspinnerPatientConsent.getSelectedView();
    if (mspinnerPatientConsent.getSelectedItem().toString().contains("No"));{
        errorText.setText("Patient Must Consent to Be Registered");
        errorText.setError("");
    }
    if (mspinnerPatientConsent.getSelectedItem().toString().contains(" "));{
        errorText.setText("Patient Must Consent to Be Registered");
        errorText.setError("");
        no_error = false;
    }

我真的是新来的,所以这可能是我看不出问题的原因。我很感激任何有帮助的投入。谢谢!

共有1个答案

翟俊
2023-03-14

不要使用选定的项字符串,而是使用

mspinnerPatientConsent.getSelectedItemPosition()

这将返回所选项的索引。

if (mspinnerPatientConsent.getSelectedItemPosition()==0);{
    errorText.setText("Patient Must Consent to Be Registered");
    errorText.setError("");
}
if (mspinnerPatientConsent.getSelectedItemPosition()==1);{
    errorText.setText("Patient Must Consent to Be Registered");
    errorText.setError("");
    no_error = false;
}
 类似资料:
  • 我需要解决一个问题与Webview和方法shouldoverrideurlloading。 我想显示一条消息,表明用户的手机上没有安装twitter应用程序

  • 在最新的Android Studio(IntelliJ)中创建了一个新项目后,我收到了一条错误消息: Moverover,如何在Android studio(IntelliJ)中显示之前在Android Eclipse中的UI? Gradle项目刷新失败: 错误:无法启动守护进程。 此问题可能是由守护程序的不正确配置引起的。例如,使用了无法识别的JVM选项。请参阅关于守护程序的用户指南章节。 请阅

  • 我有一个小要求写标准化国际化javax.validation错误消息在这种格式 @NotNull私有字符串名称; @最大(10)个私人年龄; 那么在这种情况下,错误消息应该作为 “字段名不为空” “现场年龄不大于或等于10” 如何以更动态的方式实现这一点,而不是在注释中对消息或变量名称进行硬编码。

  • 我对JAVA web应用程序非常陌生,所以请记住这一点。我承担了一个非常大的项目,令人望而生畏。我终于修复了Maven依赖,现在在Tomcat上运行时遇到了第一个错误。 包含eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl模块的Spring配置:

  • MySQL说:文档 1064年的今天,您的SQL语法出现错误;查看与您的MariaDB服务器版本对应的手册,了解第2行“@id INT AS BEGIN SET NO COUNT ON”附近使用的正确语法