androidandroid-listviewsimplecursoradapterandroid-loadermanagerandroid-viewbinder

LoadManager, SimpleCursorAdapter, ViewBinder - no URI?


I am trying to implement LoaderManager since its taking a while to load the rows into my ListView. All of the examples I have found online keep referring to a CONTENT_URI - something which I don't have.

Here's my old code for loading my ListView content:

  @Override
  public void onCreate( Bundle savedInstanceState )
  {
  ...
    String path = "/sdcard/mytunesdb.sqlite";   // Warning, yes, I know..

    db = SQLiteDatabase.openDatabase( path, null, 0 );

    lvCustomList = (ListView) findViewById( R.id.lv_custom_list );

    String[] columns = new String[] { "Name" };

    // THE XML DEFINED VIEWS FOR EACH FIELD TO BE BOUND TO
    int[] to = new int[] { R.id.lv_tune };  

    Cursor c = db.rawQuery( "SELECT rowid _id, Name FROM Tune ORDER BY Name", null );

    cAdapter = new MySimpleCursorAdapter( this, R.layout.like_hate_row, c, columns, to, 0 );

    viewBinder = new CustomViewBinder();

    cAdapter.setViewBinder( (ViewBinder) viewBinder );

    lvCustomList.setAdapter( cAdapter );

OK, so I start implementing the LoaderManager callbacks after changing the above code so that the cAdapter is created with null projection (null instead of 'columns' parameter). This is how I far I get.. How do I put my rawQuery into the onCreateLoader method?

  @Override
  public Loader<Cursor> onCreateLoader(int id, Bundle args) 
  {
    String[] columns = new String[] { "Name" };

!!! HELP - I don't have a CONTENT_URI - my database is external - what do I put below?   
    CursorLoader cursorLoader = new CursorLoader( getActivity(),
              TutListProvider.CONTENT_URI, columns, null, null, null);

     return cursorLoader;
  }

  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) 
  {
    cAdapter.swapCursor( cursor );
  }

  @Override
  public void onLoaderReset(Loader<Cursor> loader) 
  {
    cAdapter.swapCursor( null );
  }

Do I need to keep the URI code and implement a ContentProvider for my SQL database instead??


Solution

  • I figured this out with the help of SimpleCursorLoader mentioned in other StackOverlow posts. I have new problems, but at the below link you will find my solution.

    My Solution