有人能告诉我实现这一目标的正确方法。
我已经从sqlite查询设置了一个hashmap,如下所示
public HashMap<String, String> getData(){
HashMap<String,String> user = new HashMap<String,String>();
String selectQuery = "SELECT * FROM " + TABLE_DEVICES;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if(cursor.getCount() > 0){
user.put("device_name", cursor.getString(1));
user.put("id", cursor.getString(3));
}
cursor.close();
db.close();
// return user
return user;
}
然后我想要一个显示设备名称的微调器,但是当选择它的id然后用于下一个动作
我在想这样的事情,但我不确定究竟是怎么回事。
private void loadLockScreenSpinner() {
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
HashMap<String,String> hm = db.getData();
String device_name = hm.get("device_name");
String id = hm.get("id");
ArrayAdapter<HashMap<String, String>> adapter = new ArrayAdapter<HashMap<String,String>>(this, android.R.layout.simple_spinner_item);
adapter.add(hm);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
devicesSpinner.setAdapter(adapter);
devicesSpinner.setWillNotDraw(false);
}
不确定在onItemSelected
中放入什么