2 回答
TA贡献1788条经验 获得超4个赞
Add this function to your DatabaseHelper.java
public boolean userExistance(String emailOrPhone, String pwd){
String sql = "select * from " + TABLE_NAME + " where ("+ COL_3 +" = " + emailOrPhone +" OR "+ COL_4 +" = "+ emailOrPhone+ ") AND " + COL_5 + " = " + pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if(cursor.getCount() > 0)
return true;
else
return false;
}
Then add call this function from your LoginActivity.java
DatabaseHelper mydb;
mydb = new DatabaseHelper(LoginActivity.this);
boolean exists = mydb.userExistance();
if(exists)
{
Intent intent = new Intent(Login.this, Parent_Home.class);
Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();
}
TA贡献1875条经验 获得超3个赞
在您的课程中添加以下方法DatabaseHelper。
public ArrayList<ParentModel> getParentData(String emailOrPhone,String pwd){
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "SELECT * FROM " + TABLE_NAME+" WHERE ("+COL_3+"= "+emailOrPhone+" OR "+COL_4 +" = "+emailOrPhone+") AND "+COL_5 +" = "+pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.moveToFirst()) {
do {
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
}
while (cursor.moveToNext());
}
return list;
}
并使用如下代码:
if (mydb.getParentData(editTextEmailPhone.getText().toString(),editTextPassword.getText().toString()).size()>0)
{
progressDialog.dismiss();
SharedPrefs.saveSharedSetting(this, "CaptainCode", "false");
Intent intent = new Intent(Login.this, Parent_Home.class);
Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();
}
不要忘记初始化DatabaseHelper mydb。
添加回答
举报