Здравствуйте!
Есть БД SQLITE, в которой две несвязанные таблицы. Данными из одной таблицы один ListView заполняется, и все работает хорошо. Сделано так:
String[] from =new String[]{h_db.COLUMN_ID,h_db.COLUMN_NAME,h_db.COLUMN_POINTS}; int[] to = new int[]{R.id.h_item_tv1,R.id.h_item_tv2, R.id.h_item_tv3}; scAdapter = new SimpleCursorAdapter(this,R.layout.h_item, null, from, to, 0); h_lv = (ListView)findViewById(R.id.h_listView); h_lv.setAdapter(scAdapter); this.getLoaderManager().initLoader(0,null, this);
...
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new MyCursorLoader(this, db);
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
scAdapter.swapCursor(cursor);
}
@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
}
static class MyCursorLoader extends CursorLoader {
h_db db;
public MyCursorLoader(Context context, h_db db) {
super(context);
this.db = db;
}
@Override
public Cursor loadInBackground() {
Cursor cursor = db.getAllData();
return cursor;
}
}`
В другом активити заполняем другой ListView таким же способом. Из лога видно, что Adapter получает из БД все, что ему нужно(нет ошибок, что не существует чего-то в БД). При этом он не заполняет ListView.
String[] from = new String[]{h_db.COLUMN_ACHIEV_ACH, h_db.COLUMN_COUNT_ACH, h_db.COLUMN_COST_ACH};
int[] to = new int[]{R.id.a_item_ach, R.id.a_item_count, R.id.a_item_cost};
scAdapter1 = new SimpleCursorAdapter(this, R.layout.a_item, null, from, to, 0);
a_lv.setAdapter(scAdapter1);
this.getLoaderManager().initLoader(0,null, this);
...
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new MyCursorLoader(this, db);
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
scAdapter1.swapCursor(cursor);
}
@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
}
static class MyCursorLoader extends CursorLoader {
h_db db;
public MyCursorLoader(Context context, h_db db) {
super(context);
this.db = db;
}
@Override
public Cursor loadInBackground() {
Cursor cursor = db.getAllDataAch();
return cursor;
}
Собственно, курсоры с нужной инфой из БД получаю так:
public Cursor getAllData() {
return mDB.query(DB_TABLE, null, null, null, null, null, null);
}
public Cursor getAllDataAch() {
return mDB.query(DB_TABLE_ACH, null, null, null, null, null, null);
}
В OnCreate для БД, следующий код:
db.execSQL(DB_CREATE);
ContentValues cv = new ContentValues();
for (int i = 1; i < 25; i++) {
cv.put(COLUMN_NAME, "yoba" + i);
cv.put(COLUMN_POINTS, 2213-(2*i));
db.insert(DB_TABLE, null, cv);
}
db.execSQL(DB_CREATE_ACH);
ContentValues cv1 = new ContentValues();
for (int i = 0; i == achs.length; i++) {
cv1.put(COLUMN_ACHIEV_ACH, achs[i]);
cv1.put(COLUMN_COUNT_ACH, 0);
cv1.put(COLUMN_COST_ACH, cost[i]);
db.insert(DB_TABLE_ACH,null,cv1);
}
Как быть, почему не заполняется второй ListView?