我通过如何从 sqllite 数据库获取数据并将其设置为列表视图来获得此代码:
Cursor cursor = dbAdapter.getAllIncomingData();
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
Log.d("ADD/EDIT", cursor.getCount() + "");
int size = cursor.getCount();
incomingDataList = new ArrayList<IncomingData>(size);
incomingStringList = new ArrayList<String>(size);
for (int i = 0; i < size; i++) {
String serial = cursor.getString(cursor
.getColumnIndex("serial"));
String mapurl = cursor.getString(cursor
.getColumnIndex("mapurl"));
String datetime = cursor.getString(cursor
.getColumnIndex("datetime"));
// Device device=new Device(id, label, serial,
// contact);
Device dev = dbAdapter.getDeviceBySerial(serial);
IncomingData inData = new IncomingData(serial, mapurl,
datetime);
inData.setLabel(dev.getLabel());
inData.setContact(dev.getContact());
incomingDataList.add(inData);
cursor.moveToNext();
}
inAdapter = new IncomingDataArrayAdapter(
MatchpointHistoryActivity.this, R.layout.history_item,
incomingDataList);
historyList.setAdapter(inAdapter);
}
数据库的数据正在通过接收短信更新,我已经在接收器类中编写了插入查询,现在我希望如果添加或删除新数据,那么光标将得到通知并将适配器重置为列表视图,我必须重新启动活动才能查看更改,但我需要立即通知更改。我不想一直用计时器来做这些事情,还有其他方法吗?