這裏是我的android代碼登錄option.help我發現問題出在哪裏。如何創建Android登錄
我DatabaseHelper類:
public String getAllData(String name) {
// TODO Auto-generated method stub
SQLiteDatabase db=this.getReadableDatabase();
//查詢檢索名稱,並通過
Cursor res = db.rawQuery("select User_Name,User_Pass from "+Table_Name, null);
String a,b;
b="not found";
if(res.moveToFirst()){
do{
a=res.getString(1);
//check name
if(a.equals(name)){
b=res.getString(3);
break;
}
}while(res.moveToNext());
}
//return corresponding password
return b;
}
我的活動類:
public void showData(){
submitButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
name=userNameEditText.getText().toString();
password=passwordEditText.getText().toString();
String pass=myDb.getAllData(name);
//matching password
if(password.equals(pass)){
Intent intent=new Intent(UserActivity.this,Meal_Information_Activity.class);
startActivity(intent);
}
else{
Toast.makeText(getBaseContext(),"Password doesn't match", Toast.LENGTH_LONG).show();
}
}
});
}