我想用多种类型的用户创建登录活动。该登录名与MySQL连接。多个选择是“审阅者”和“非审阅者”。现在,我使用Spinner和从string.xml调用的值。在“用户”表中,有一些列,例如“用户名”,“密码”和“用户类型”。例如,用户“ peter”是“审阅者”,如果他使用的用户名,密码和用户类型正确,他将能够登录。我怎么解决这个问题?下面是我的代码。
//登录活动公共类MainActivity扩展了AppCompatActivity {
private static final String KEY_USERNAME = "username";
private static final String LOGIN_URL = "http://lienawan.xyz/login.php";
private SharedPreferences.Editor loginPrefsEditor;
private EditText etEmail;
private EditText etPassword;
private CheckBox chkMe;
ArrayAdapter adapter;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
Objects.requireNonNull(getSupportActionBar()).hide(); // hide the title ba
setContentView(R.layout.activity_main);
etEmail = findViewById(R.id.etEmail);
etPassword = findViewById(R.id.etPassword);
chkMe = findViewById(R.id.chkMe);
SharedPreferences loginPreferences = getSharedPreferences("loginPrefs", MODE_PRIVATE);
loginPrefsEditor = loginPreferences.edit();
boolean saveLogin = loginPreferences.getBoolean("saveLogin", false);
if (saveLogin) {
etEmail.setText(loginPreferences.getString("username", ""));
etPassword.setText(loginPreferences.getString("password", ""));
chkMe.setChecked(true);
}
Spinner spCategory = findViewById(R.id.spCategory);
adapter = ArrayAdapter.createFromResource(this,R.array.usertype,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spCategory.setAdapter(adapter);
spCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView> parent) {
}
});