【发布时间】:2018-08-04 16:40:04
【问题描述】:
我正在尝试创建一个登录表单,您可以在其中从微调器中选择一个项目,然后您需要在文本字段中输入正确的代码才能继续。这就是我得到的。
Spinner schoolList = findViewById(R.id.schoolList);
ArrayAdapter<String> schoolListAdapter = new ArrayAdapter<String>(CreateAccount.this, android.R.layout.simple_spinner_dropdown_item, schools);
schoolList.setAdapter(schoolListAdapter);
private String[] schools = new String[]{
"School 1",
"School 2,
"School 3"
};
private String[] schoolCodeArray = new String[] {
"password1",
"password2",
"password3"
};
我知道您可以检查学校 1 = 密码 1 等,但此列表会很长,因此我正在寻找更好的方法。例如获取所选学校的索引并检查该索引是否等于 schoolCodeArray 中的索引并与文本字段中的内容匹配。我希望你明白我在找什么。感谢所有帮助!
【问题讨论】:
-
创建一个将学校和代码结合在一起的类;然后创建该类的单个数组。
-
为什么不使用 Array of Array? String[][] = new String[]{ new String[] {"School1", "Password1"}, new String[] {"School 2", "Password2" } };
标签: java android indexing spinner