我在我的应用程序中设置了一个内容提供程序并使用 LoaderManager 加载数据,但是我在将光标交换到光标适配器时遇到了麻烦,我测试了光标是否正在返回数据并且它正在返回!追踪问题,似乎ad.swapCursor(cursor);
是问题所在。
你认为我在这里做错了什么?它可能是内容提供者吗?
public class Main extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor> {
public SimpleCursorAdapter ad;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getLoaderManager().initLoader(0, null, Main.this) != null);
ad = new SimpleCursorAdapter(this, android.R.id.list, null, null, null, 0);
}
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// TODO Auto-generated method stub
Toast.makeText(this, "Started!", Toast.LENGTH_SHORT).show();
CursorLoader cursorLoader = new CursorLoader(getBaseContext(),
AviatorContentProvider.LISTS_URI, null, null, null, null);
if(cursorLoader != null){
Toast.makeText(this, "This thing is heavy!", Toast.LENGTH_SHORT).show();
}
return cursorLoader;
}
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
// TODO Auto-generated method stub
ad.swapCursor(cursor);
}
public void onLoaderReset(Loader<Cursor> arg0) {
// TODO Auto-generated method stub
}}
谢谢