0
我有一个非常具体的任务,需要使用下列元素来完成。 我必须开发一个登录页面,在那个页面上我必须创建一个我已经完成的下拉框(微调框)。微调包含4个名字。但是,当从下拉框中选择名称时,用户必须输入密码(4位数字)。这是棘手的地方,我需要帮助。我必须使用数组来连接来自微调控制器的名称和与每个用户相关的一组4个硬编码密码,例如, user1密码是1234,否则密码无效。 我已经问过关于这个特定主题的帮助,有些人提出了不同的方法,但我必须强调,我需要为这个页面使用并行数组。 我将包含一些我一直在尝试使用的代码。我的问题是如何将我的阵列连接到spinners,以便用户选择必须输入他们特定的密码? 目前我无法在输入时将用户连接到他们的特定密码。阵列和纺纱器
my spinner contains four names// spinner=(Spinner) findViewById(R.id.names);
ArrayAdapter adapter=ArrayAdapter.createFromResource(this,
R.array.names,android.R.layout.simple_spinner_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
my passcode login //public void onTextChanged(CharSequence s, int start, int before,
int count)
{
if (passcodeEntered.getText().toString().length() == 4)
{
if ((passcodeEntered.getText().toString().equalsIgnoreCase("1234")))
{
Intent myIntent = new Intent(MainActivity.this, Summary.class);
startActivity(myIntent);
} else
{
Toast.makeText(getBaseContext(), "Invalid Passcode",
Toast.LENGTH_SHORT).show();
finally here is some code I was trying to use in my arrays//
public void passCodes(){
String[] names = {"user1", "user2", "user3", "user4"};
String [] passcodes = {"1234", "4321", "5678", "8765"};
int passcode = keyboard.nextInt();
for (int i = 0; i < names.length; i++)
{
if (passcodes[i]==passcode){
System.out.println("Go to next page");
System.out.println(names[i]);
}
}
堆栈溢出用于编程问题。你的问题是什么? – CommonsWare 2014-12-07 16:19:53
问题是什么? – 2014-12-07 16:40:52
我不知道如何让它工作。我无法获得与密码相匹配的名字。 – ExarchTemplar 2014-12-07 16:43:46