驗證我有3 Java文件 我)DBAdapter.java II)signup.java III)login.java 四一個是菜單,但沒有必要在此提及。安卓:如何創建登錄頁面是從數據庫
現在我想這樣做,當用戶來登錄頁面,並在編輯視圖中輸入用戶名和密碼,檢查數據庫中的數據和重定向到菜單,如果發現匹配。 我不知道如何做到這一點,這裏是DBAdapter.java我的代碼文件和login.java
DBAdapter.java
public class DBAdapter
{
public static final String KEY_ROWID = "_id";
public static final String KEY_FIRSTNAME = "FirstName";
public static final String KEY_LASTNAME = "LastName";
public static final String KEY_USERNAME = "UserName";
public static final String KEY_PASSWORD = "Password";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "master";
private static final String DATABASE_TABLE = "register";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
"create table titles (_id integer primary key autoincrement, "
+ "FirstName text not null, LastName text not null, "
+ "UserName text not null, Password text not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS titles");
onCreate(db);
}
}
login.java
public class login extends Activity {
private EditText username;
private EditText password;
public String user_name;
public String pass_word;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
username = (EditText) findViewById(R.id.ev_unameLogin);
password = (EditText) findViewById(R.id.ev_passwordLogin);
final Button button = (Button) findViewById(R.id.btn_login);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
user_name = username.getText().toString();
pass_word = password.getText().toString();
Intent goToNextActivity = new Intent(getApplicationContext(), menu.class);
startActivity(goToNextActivity);
}
});
}
}
那麼什麼我應該更新這兩個文件..
非常感謝提前
究竟是什麼問題?你不知道如何完成什麼? – Guy 2011-02-28 09:20:34
que是我如何在數據庫中提取檢索數據(在user_name和pass_word中)。總之是註冊與否。 – Harry 2011-02-28 09:25:33