开发者

getLoaderManager in ListActivity

I wish to implement a Loader for in a ListActivity but the activity do not recognize getLoaderMan开发者_如何学Pythonager.

     @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);
}


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.


i think you probably use below instead

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

if you use the support v4 package

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜