我希望在ListActivity中实现一个Loader,但 Activity 无法识别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);
}

最佳答案

如果您的应用只能在API级别11或更高级别上运行,请适当设置构建目标,该方法将可用。

但是,如果您使用的是Android兼容性库来支持API级别11之前的加载器,则不能使用ListActivity。您必须从FragmentActivity继承。可以使用ListFragment,也可以只使用您自己管理的简单ListView

关于android - ListActivity中的getLoaderManager,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7622913/

10-10 10:12