私は2つのテーブルを持っています。 tblsubjectとtbltopicsです。私は、すべての科目をすべての科目でリストアップしたいと思います。私は私のリストビュー移入これはListViewには、Android Studioのデータベースに2つのテーブルがあります
getSubject()
public Cursor getAllSubject() {
String where = null;
Cursor c = db.query(true, DATABASE_TABLE, ALL_KEYS, where, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
countTopics()
public int countTopics(long subjectid) {
String where = KEY_TOPICSUBJECTID + " = " + subjectid;
Cursor c = db.query(true, DATABASE_TABLE2, ALL_KEYS2,
where, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c.getCount();
}
viewList()
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void viewList() {
Cursor cursor = myDb.getAllSubject();
String[] fromFieldNames = new String[]{DBAdapter.KEY_SUBJECTID, DBAdapter.KEY_SUBJECT, DBAdapter.KEY_DATESUBJECT};
int[] toViewIds = new int[]{R.id.txtViewSubjectId, R.id.txtViewSubject, R.id.txtSubjectDateCreated};
SimpleCursorAdapter myCursorAdapter;
myCursorAdapter = new SimpleCursorAdapter(getBaseContext(), R.layout.activity_view_the_list, cursor, fromFieldNames, toViewIds, 0);
ListView myList = (ListView) findViewById(R.id.listView);
myList.setAdapter(myCursorAdapter);
}
私の問題は、どのようにトピックごとに件数を追加するかです。私は科目を表示することができます。ありがとうございました。
前処理情報 –
なぜあなたはリストビューのカーソルアダプタを作成しませんか?カーソルを取得して、必要なデータに必要なクエリを生成します – xanexpt