Android 游标加载程序更改游标()不';刷新列表视图

Android 游标加载程序更改游标()不';刷新列表视图,android,listview,android-contentprovider,android-cursorloader,Android,Listview,Android Contentprovider,Android Cursorloader,在许多项目中,我使用resest方法对服务器-listView-contentprovider进行测试,效果很好。然而,我面临着一个非常奇怪的问题——notifyChange(uri,null)在插入或删除数据时,不会自动刷新listview中的数据 { ListView listView = (ListView) findViewById(R.id.list); View header = View.inflate(this, R.layout.header, nu

在许多项目中,我使用resest方法对服务器-
listView
-contentprovider进行测试,效果很好。然而,我面临着一个非常奇怪的问题——
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;
{
ListView ListView=(ListView)findViewById(R.id.list);
视图标题=视图。充气(此,R.layout.header,空);
addHeaderView(标题);
adapter=新适配器(this,R.layout.item,null,true);
setAdapter(适配器);
getSupportLoaderManager().restartLoader(0,null,this);
}
@凌驾
公共加载器onCreateLoader(int arg0,Bundle arg1){
返回新的游标加载程序(this,Statuses.URI,null,null,null);
}
@凌驾
公共void onLoadFinished(加载器arg0,光标arg1){
适配器.changeCursor(arg1);
}
@凌驾
公共void onLoaderReset(加载程序arg0){
adapter.changeCursor(null);
}
//内容提供者的插入方法
long id=db.getWritableDatabase().insertWithOnConflict(表,null,值,SQLiteDatabase.CONFLICT\u REPLACE);
Uri newUri=Uri.withAppendedPath(Uri,Long.toString(id));
cr.notifyChange(newUri,null);
返回newUri;
//contentn提供者的delete方法
int count=db.getWritableDatabase().delete(表、选择、选择);
cr.notifyChange(uri,null);
返回计数;

你觉得这个代码有什么问题吗

已解决。在游标返回之前忘记添加Uri