在一张桌子上,我这样做:
public static String[] FROM_Benzinarii_onList = {DBConstants.Denumire_Benzinarie, DBConstants.Adresa, DBConstants.Distance, _ID};
public Cursor getStations_List(){
db = helper.getReadableDatabase();
return db.query(DBConstants.TABELA_BENZINARII, FROM_Benzinarii_onList, null, null, null, null, null);
然后构造适配器:
int[] values = {R.id.tv_benzinarie,R.id.tv_adresa,R.id.tv_dist}
Cursor cursor = getStations_List();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getBaseContext(), R.layout.item_list, cursor,FROM_Benzinarii_onList, values);
setListAdapter(adapter);
但是现在我需要一个额外的列,价格,来自另一个表,我无法获得游标。我已经尝试了下面的代码以及许多其他代码。
public static String[] FROM_Benzinarii_onList = {DBConstants.Denumire_Benzinarie, DBConstants.Adresa, DBConstants.Distance, DBConstants.Pret, _ID};
public Cursor getStations_List(){
db = helper.getReadableDatabase();
String sql = " select " + DBConstants.TABELA_BENZINARII + "." + DBConstants.Denumire_Benzinarie + "," + DBConstants.TABELA_BENZINARII + "." + DBConstants.Adresa
+ "," + DBConstants.TABELA_BENZINARII + "." + DBConstants.Distance + "," + DBConstants.TABELA_PRETURI + "." + DBConstants.Pret
+ " from " + DBConstants.TABELA_PRETURI + "," + DBConstants.TABELA_BENZINARII
+ " where " + DBConstants.TABELA_BENZINARII + "." + DBConstants.ID_Benzinarie + " = " + DBConstants.TABELA_PRETURI + "." + DBConstants.ID_Benz;
return db.rawQuery(sql, null);
}
然后用同样的方法构造SimpleAdapter(不知道对不对!?)
int[] values = {R.id.tv_benzinarie,R.id.tv_adresa,R.id.tv_dist,R.id.tv_pret};
Cursor cursor = getStations_List();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getBaseContext(), R.layout.item_list, cursor,FROM_Benzinarii_onList, values);
setListAdapter(adapter);
我得到:
Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
我不知道我的新光标是否与我有关,FROM_Benzinarii_onList
但我不能db.query
在这里使用请帮助!