userpassword=(EditText)findViewById(R.id.editText);
String userName=username.getText().toString();
String passWord=userpassword.getText().toString();
if (login(userName,passWord)) {
Toast.makeText(MainActivity.this, "登陆成功(ZY,111)", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this, "登陆失败", Toast.LENGTH_SHORT).show();
}
}
//验证登录
public boolean login(String username,String password) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
String sql = "select * from userData where name=? and password=?";
Cursor cursor = db.rawQuery(sql, new String[] {username, password});
if (cursor.moveToFirst()) {
cursor.close();
return true;
}
return false;
}
好了,就酱。
|