我在许多项目中使用服务器的方法resueest listView
- 内容提供者并且效果很好。但是我遇到了一个非常奇怪的问题 -如果我也插入或删除数据,notifyChange
(uri, null) 不会自动刷新数据。listview
{
ListView listView = (ListView) findViewById(R.id.list);
View header = View.inflate(this, R.layout.header, null);
listView.addHeaderView(header);
adapter = new Adapter(this, R.layout.item, null, true);
listView.setAdapter(adapter);
getSupportLoaderManager().restartLoader(0, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(this, Statuses.URI, null , null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
adapter.changeCursor(arg1);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
adapter.changeCursor(null);
}
// inset method of content provider
long id = db.getWritableDatabase().insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE);
Uri newUri = Uri.withAppendedPath(uri, Long.toString(id));
cr.notifyChange(newUri, null);
return newUri;
//delete method of contetn provider
int count = db.getWritableDatabase().delete(table, selection, selectionArgs);
cr.notifyChange(uri, null);
return count;
您对此代码有任何问题吗?