我正在尝试从我的数据库中填充一个微调器,但是当我获取数据时不希望它们按年份排序,即使在查询中指出这一点。
这就是我获取数据的方式
public Set<String> getAllData(int getData,String[] args, String qry) {
Set<String> set = new HashSet<String>();
String selectQuery = qry ;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery , args);
if (cursor.moveToFirst()) {
do {
set.add(cursor.getString(getData));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return set;
}
这是查询
String myQry = "SELECT * FROM Car ORDER BY year";
并加载微调器
private void loadSpinner(Spinner mySpinner, int getData, String[] args, String qry) {
// here i used Set Because Set doesn't allow duplicates.
Set<String> set = db.getAllData(getData, args, qry);
List<String> list = new ArrayList<String>(set);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mySpinner.setAdapter(adapter);
mySpinner.setWillNotDraw(false);
}
谢谢