【发布时间】:2017-11-24 12:54:56
【问题描述】:
我正在使用包含三个表的数据库,学生、答案、问题 答案表包含studentid、questionid、answer 我用三个表在 SQLITE 中构建了一个数据库,所以当应用程序加载时,我设置学生去检查答案。 问题是从这个表中获取历史记录,在 ListView 中,我之前使用了一个适配器,但是在它只是从表中显示直接信息之前这很容易,但是对于表答案,我必须获取 studentid 并显示名称,获取 questionid 并显示问题本身。 适配器不起作用,因为该类没有我想要显示的相同内容,所以我制作了一个可以给我想要的信息的方法:
public ArrayList getTableHisto() {
ArrayList lst = new ArrayList();
int zise = lst.size();
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(" SELECT Q." + KEY_QUESTION + " , U." + KEY_NOM + " , U." + KEY_PRENOM + " , A." + KEY_DATE + " , " + KEY_REPONSE + " from " + TABLE_QUESTION + " Q, " + TABLE_USER + " U, " + TABLE_ANSWER + " A WHERE Q." + KEY_ID_QUESTION + " = A." + KEY_ID_QUESTION + "AND A." + KEY_MATRICULE + " = U." + KEY_MATRICULE, null);
if (c.moveToFirst()) {
while (c.isAfterLast() == false) {
String nom = c.getString(c.getColumnIndex(KEY_NOM)).toString();
// String prenom = c.getString(c.getColumnIndex(KEY_PRENOM)).toString();
String quest = c.getString(c.getColumnIndex(KEY_QUESTION)).toString();
String reponse = c.getString(c.getColumnIndex(KEY_REPONSE)).toString();
String date = c.getString(c.getColumnIndex(KEY_DATE)).toString();
lst.add(nom);
// lst.add(prenom);
lst.add(quest);
lst.add(reponse);
lst.add(date);
c.moveToNext();
}
}
return lst;
}
我认为它正在工作,因为我尝试了 sql 查询,但问题是使其适应 histrow.java 中有四列的 ListView:
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="horizontal"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView
android:id="@+id/hname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="nom" />
<TextView
android:id="@+id/hquest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ques" />
<TextView
android:id="@+id/hrep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="rep" />
<TextView
android:id="@+id/hdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="date" />
</LinearLayout>
历史页面只有一个 ID 为 hist 的 ListView 如果有人有任何想法,请不要犹豫。 谢谢
【问题讨论】: