Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getLoaderManager in ListActivity

I wish to implement a Loader for in a ListActivity but the activity do not recognize 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);
}
like image 789
Gaurav Agarwal Avatar asked Oct 01 '11 20:10

Gaurav Agarwal


2 Answers

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.

like image 171
CommonsWare Avatar answered Nov 15 '22 10:11

CommonsWare


i think you probably use below instead

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

if you use the support v4 package

like image 11
brightown Avatar answered Nov 15 '22 09:11

brightown