在我的应用程序中,我有两个不同行的表。 我试图用cursorAdapter在listView上显示两个表。 但是cursorAdapter只查询一个要显示的表。 我如何设置两个表两个cursorAdapter? 这是我的代码:
MainActivity:
hand = new DbHandler(getActivity());
Cursor c = hand.getDayCursor(workName);
adapterC = new CustomCursorAdapter(getActivity(), c, 0);
lv.setAdapter(adapterC);
来自DbHandler:
public Cursor getSettingCursor(String workName) {
Cursor c = null;
try {
open();
c = myDb.query(TABLE_DAY, null, "workName=?", new String[]{workName}, null, null, null, null);
c.getInt(0);
c.getString(1);
c.getFloat(2);
c.getFloat(3);
c.getInt(4);
c.getInt(5);
c.getInt(6);
c.getInt(7);
c.getInt(8);
c.getFloat(9);
c.getFloat(10);
c.getFloat(11);
c.getInt(12);
c.getInt(13);
c.getFloat(14);
c.getFloat(15);
c.getFloat(16);
c.getInt(17);
c.getInt(18);
c.getFloat(19);
c.getFloat(20);
c.getFloat(21);
} catch (Exception e) {
// TODO: handle exception
}finally{
close();
}
return c;
}
public Cursor getDayCursor(String workName) {
Cursor c = null;
try {
open();
c = myDb.query(TABLE_DAY, null, "workName=?", new String[]{workName}, null, null, null, null);
c.getInt(0);
c.getString(1);
c.getFloat(2);
c.getFloat(3);
c.getInt(4);
c.getInt(5);
c.getInt(6);
c.getInt(7);
c.getInt(8);
c.getFloat(9);
c.getFloat(10);
c.getFloat(11);
c.getInt(12);
c.getInt(13);
c.getFloat(14);
c.getFloat(15);
c.getFloat(16);
c.getInt(17);
c.getInt(18);
c.getFloat(19);
c.getFloat(20);
c.getFloat(21);
} catch (Exception e) {
// TODO: handle exception
}finally{
close();
}
return c;
}
的CursorAdapter:
@Override
public void bindView(View view, Context context, Cursor cursor) {
int dateDay = cursor.getInt(cursor.getColumnIndex(DbHandler.DATE_DAY));
int dateMonth = cursor.getInt(cursor.getColumnIndex(DbHandler.DATE_MONTH));
int dateYear = cursor.getInt(cursor.getColumnIndex(DbHandler.DATE_YEAR)); .....
}
还有一个问题,在Dbhandler中,我是否必须放置" c.getInt(0); ... c.getString(1); .."? 感谢他们的帮助..