我在DatabaseHandler.java中有函数
/**
* Getting user data from database
* */
public HashMap<String, String> getUserDetails(){
HashMap<String,String> user = new HashMap<String,String>();
String selectQuery = "SELECT * FROM " + TABLE_LOGIN;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if(cursor.getCount() > 0){
user.put("id_user", cursor.getString(1));
user.put("name", cursor.getString(2));
user.put("email", cursor.getString(3));
user.put("regid", cursor.getString(4));
user.put("jenis_kelamin", cursor.getString(5));
user.put("tanggal_lahir", cursor.getString(6));
user.put("instansi", cursor.getString(7));
user.put("jabatan", cursor.getString(8));
user.put("dibuat_at", cursor.getString(9));
}
cursor.close();
db.close();
// return user
return user;
}
以及如何从数据库获取数据id_user,名称,电子邮件等以在MainActivity.java中显示的问题 请帮忙
答案 0 :(得分:0)
创建新的HashMap:
HashMap<String,String> hashMap = getUserDetails();
并在您的MainActivity.java中使用:
hashMap.get(text);
文本字段是一个字符串,应该是“id_user”,“name”,“email”等。
P.S:如果我没错,你总是从第一行开始详细说明..