【发布时间】:2014-03-04 18:42:51
【问题描述】:
我目前正在使用以下查询从我的 sqlite 数据库中提取数据:
public List<Catalog> getAllExercise(String ex_class, String period, int age1, int age2, int distance1, int distance2, String vo2max, String language) {
List<Catalog> exerciseList = new ArrayList<Catalog>();
String selectQuery = null;
selectQuery = "SELECT catalog.ex_id, translation.ex_desc, translation.trans_id FROM " + TABLE_CATALOG +", " + TABLE_TRANSLATION + " WHERE catalog.ex_id = translation.ex_id AND catalog.ex_class = " + ex_class + " AND (catalog.age BETWEEN " + age1 + " AND " + age2 + ") AND (catalog.pr_comp_distance BETWEEN " + distance1 + " AND " + distance2 + ") AND translation.language = " + language + ";";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()) {
do {
Catalog exercise = new Catalog();
exercise.setId(cursor.getInt(cursor.getColumnIndex(KEY_EX_ID)));
exercise.setExDesc(cursor.getString(cursor.getColumnIndex(KEY_EX_DESC)));
exerciseList.add(exercise);
} while (cursor.moveToNext());
}
return exerciseList;
}
从我的数据库中选择 ID 和描述字段非常简单。
现在我想在我的 onCreate 函数中使用以下代码在列表视图中显示它:
DatabaseHelper db = new DatabaseHelper(getApplicationContext());
ListView list_exercises = (ListView)findViewById(R.id.list_training_sessions);
List<Catalog> exercise = new ArrayList<Catalog>();
exercise = db.getAllExercise(ex_class, period, age1, age2, distance1, distance2, vo2max, "'" + language + "'");
ArrayAdapter<Catalog> adapter = new ArrayAdapter<Catalog>(this, android.R.layout.simple_expandable_list_item_1, exercise);
list_exercises.setAdapter(adapter);
我在我的列表中得到了适量的结果,但它只显示如下:
info.olbrecht.sqlite.model.Catalog@41000dd0
我猜这是我的包名?
PS:如果我使用Log.d 会显示正确的值,那么我猜我的 listView 或转换为 String 的某个地方一定犯了错误?不太确定...
我做错了什么?
提前谢谢
【问题讨论】: