我想使用数据库上的标志列使登录按钮分派到2个不同的活动中?
如果租户登录,它将重定向到租户活动
房东登录后会重定向到其他活动?
public void onResponse(String response) {
Log.e(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
success = jObj.getInt(TAG_SUCCESS);
// Check for error node in json
if (success == 1) {
String username = jObj.getString(TAG_USERNAME);
String id = jObj.getString(TAG_ID);
Log.e("Successfully Login!", jObj.toString());
Toast.makeText(getApplicationContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(session_status, true);
editor.putString(TAG_ID, id);
editor.putString(TAG_USERNAME, username);
editor.commit();
// go to main activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra(TAG_ID, id);
intent.putExtra(TAG_USERNAME, username);
finish();
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
}
}
在log in
按钮的onClickListener()方法内部,可以放置一条if()
语句。
执行步骤
1.从用户名和密码字段获取数据,并在查询中使用该数据从数据库中检索数据
2.将检索到的数据存储在如下所示的String中,因为您只会得到一行:
String flag = cursor.getString(7); //skipping the cursor and other database part
3.现在,您可以在获取String flag
值后将if()语句放入登录按钮的onClickListener中:
if(flag.equals(landlord)){
Intent intent = new Intent(this,Landlord.class);
startActivity(intent);
}
else{
Intent intent = new Intent(this,Tenant.class);
startActivity(intent);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句