9

我希望在 ListActivity 中实现 Loader,但该活动无法识别 getLoaderManager。

     @Override
     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);


    dbHelper =  new DBHelper(this,DBNAME,FindPackageName(), TABLE_NAME);

    sql = dbHelper.getReadableDataBase();
    //Log.d("Gaurav","Database Open");
    String[] from = new String[]{"word","_id","MyList"};
    int[] to = new int[]{R.id.listrow };

    simpleCursorLoader = new SimpleCursorLoader(this, TABLE_NAME, from, null, null, null, null, null, null, sql);



    //query result will be whole database
    //cursor = sql.query(TABLE_NAME, from, null, null, null, null, null);
    //startManagingCursor(cursor); //this method is deprecated
    //Log.d(TAG,"Cursor Set");



    completerOrMyListAdapter = new CompleteOrMyListAdapter(this,
            R.layout.completeormylist_adapter, cursor, from, to, dbHelper); 
    setListAdapter(completerOrMyListAdapter);  

    // Prepare the loader.  Either re-connect with an existing one,
    // or start a new one.
    LoaderManager lm = getLoaderManager();
    //if (lm.getLoader(0) != null) {
    //    lm.initLoader(0, null, this);
    //}
    //getLoaderManager().initLoader(0, null, this);
}
4

2 回答 2

19

If your app will only run on API Level 11 or higher, set your build target appropriately, and the method will be available.

However, if you are using the Android Compatibility Library to have support for loaders before API Level 11, you cannot use ListActivity. You have to inherit from FragmentActivity. Either use a ListFragment, or just a plain ListView that you manage yourself.

于 2011-10-01T21:50:25.930 回答
11

我想你可能用下面代替

getSupportLoaderManager().initLoader(0, null, this); 

如果您使用支持 v4 包

于 2012-06-18T07:14:22.170 回答