基于电子邮件从数据库中检索用户数据
Retrieving User's data from database on the basis of email
我在数据库中有不同用户的数据,我想检索当前登录应用程序的用户的数据,我能够检索数据,但我不知道如何display/show 它在主要 Activity.
这是我的 getUserData 方法
DBHandler
public ArrayList<User> getUserData(String email){
Log.e("email", "" + email);
ArrayList<User> arrayList = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor;
String query = " select * from " +TABLE_NAME+ " where "+COLUMN_EMAIL+ "=?";
String[] select = new String[]{email};
cursor = db.rawQuery(query,select);
Log.e("Query", "" + query);
if (cursor.moveToFirst()) {
do {
String FirstName = cursor.getString(0);
String LastName = cursor.getString(1);
String Email = cursor.getString(2);
byte[] image = cursor.getBlob(5);
String gender = cursor.getString(6);
String status = cursor.getString(8);
User user = new User(FirstName, LastName, Email, image, gender, status);
arrayList.add(user);
}
while (cursor.moveToNext());
}
cursor.close();
return arrayList;}
现在我想在主屏幕上显示它Activity我该怎么做?
TextView FirstName = findViewById(R.id.FirstName);
TextView LastName = findViewById(R.id.LastName);
ArrayList<User> userArrayList = new ArrayList<User>(getUserData("user@gmail.com")); // User data stored in userArrayList now you can use userArrayList for showing data
FirstName.setText(userArrayList.get(0).getFirstName()); // get(0) Gives you first name from first position
LastName.setText(userArrayList.get(0).getLastName());
我在数据库中有不同用户的数据,我想检索当前登录应用程序的用户的数据,我能够检索数据,但我不知道如何display/show 它在主要 Activity.
这是我的 getUserData 方法
DBHandler
public ArrayList<User> getUserData(String email){
Log.e("email", "" + email);
ArrayList<User> arrayList = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor;
String query = " select * from " +TABLE_NAME+ " where "+COLUMN_EMAIL+ "=?";
String[] select = new String[]{email};
cursor = db.rawQuery(query,select);
Log.e("Query", "" + query);
if (cursor.moveToFirst()) {
do {
String FirstName = cursor.getString(0);
String LastName = cursor.getString(1);
String Email = cursor.getString(2);
byte[] image = cursor.getBlob(5);
String gender = cursor.getString(6);
String status = cursor.getString(8);
User user = new User(FirstName, LastName, Email, image, gender, status);
arrayList.add(user);
}
while (cursor.moveToNext());
}
cursor.close();
return arrayList;}
现在我想在主屏幕上显示它Activity我该怎么做?
TextView FirstName = findViewById(R.id.FirstName);
TextView LastName = findViewById(R.id.LastName);
ArrayList<User> userArrayList = new ArrayList<User>(getUserData("user@gmail.com")); // User data stored in userArrayList now you can use userArrayList for showing data
FirstName.setText(userArrayList.get(0).getFirstName()); // get(0) Gives you first name from first position
LastName.setText(userArrayList.get(0).getLastName());