In the SCHED table, ID_GROUP records the _id group from the GROUPS table. How can I, through the query query in the ListView, display instead of the key in ID_GROUP, a record from the GROUPS table by _id?

The code for creating these tables in the database:

db.execSQL("create table GROUPS (_id integer primary key autoincrement, " + "NAME_OF_GROUP text);"); db.execSQL("create table SCHED (_id integer primary key autoincrement, " + "COUPLE text, " + "PREDMET text, " + "ID_GROUP text, " + "TYPE text, " + "CAB text, " + "DAY text, " + "WEEK text);"); 

The code to display information from the database in the ListView:

 cursor = db.query("SCHED", new String[]{"_id", "COUPLE", "PREDMET", "ID_GROUP", "TYPE", "CAB","DAY", "WEEK"}, "DAY = ? AND WEEK = ?", new String[]{day, week },null, null, null); {day,week}); CursorAdapter listAdapter = new SimpleCursorAdapter(this, R.layout.list_row, cursor, new String[]{"COUPLE", "PREDMET", "ID_GROUP", "TYPE", "CAB"}, new int[]{R.id.coupleView, R.id.predmetView, R.id.groupView, R.id.typeView, R.id.cabView }, 0); listView.setAdapter(listAdapter); 
  • one
    use Left Join and everything will turn out - Saidolim

1 answer 1

try creating cursor using rawQuery

 private final String ZAPROS = "SELECT * FROM SCHED a INNER JOIN GROUPS b ON a.ID_GROUP =b._id WHERE a.DAY = ? AND a.WEEK = ?"; db.rawQuery(ZAPROS, ew String[]{day, week}); 
  • and how should a CursorAdapter look like this? - user212271
  • @ user212271 is the same, but instead of * name of the fields, specify and xml under the name of the group correct - Saidolim