我想创建一个android studio登录页面,使用存储在数组列表中的多个帐户。如何验证写入的用户名和密码是否与存储在arraylist中的用户名和密码相同
继承我在res中的数组列表:
<string-array name="user"> <item>admin</item> <item>jhon</item></string-array><string-array name="pass"> <item>admin</item> <item>littlejhon</item></string-array>
这里是我的活动代码:
import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget. CardView;import android.view.View;import android.widget.EditText;import android.widget.Toast; import java.util.HashMap;import java.util.Objects;public class PassActivity extends AppCompatActivity { EditText username; EditText password; CardView card; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pass); final String[] use = getResources().getStringArray(R.array.user); final String[] pas = getResources().getStringArray(R.array.pass); username = findViewById(R.id.username); password = findViewById(R.id.password); card = findViewById(R.id.card); card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Objects.equals(username.getText().toString(), use) && Objects.equals(password.getText().toString(),pas)) { Toast.makeText( PassActivity.this, "You have Authenticated Successfully", Toast.LENGTH_LONG) .show(); } else { Toast.makeText( PassActivity.this, "Authentication Failed", Toast.LENGTH_LONG) .show(); } } }); }}
谢谢你的帮助,希望有人有这方面的经验。谢谢..
德玛西亚99
相关分类