title: How to read an SQLite DB in android with a cursorloader?
body: <p>I'm setting up my app so that people can create groups of their friends. When a group is created, it writes 2 tables to the SQL database. The first table has a group name and a group id. The second table has 2 columns, a group id and a user id. This is working fine.</p>
  
  <p>However, now I want to be able to read from the database. I'm using a listview fragment with a <code>cursorloader</code> but I'm having trouble getting the information to display. I want to list all the group names from the first table in my list view.</p>
  
  <p>My problem is that, when I first used the <code>cursorloader</code> to list my contacts, I was using a <code>Uri</code> from the <code>content provider</code> in the <code>onCreateLoader</code> method. Specifically I had <code>CONTENT_URI</code> from the <code>ContactsContracts.Contacts</code> class. </p>
  
  <p>Example of <code>cursorloader</code> with <code>contentprovider</code>:</p>
  
  <pre><code>@Override
  public Loader&lt;Cursor&gt; onCreateLoader(int i, Bundle bundle) {
      Uri contentUri = ContactsContract.Contacts.CONTENT_URI;
      return new CursorLoader(getActivity(),contentUri,PROJECTION,SELECTION,ARGS,ORDER);
  }
  </code></pre>
  
  <p>However, without using a content provider, I don't know what to put in the <code>onCreateLoader</code> method because <code>return new CursorLoader(...)</code> requires a <code>Uri</code> in the second argument.</p>
  
  <p>Any suggestion on how I might be able to display my database data in a listview?</p>
  
  <p>fragment class code:</p>
  
  <pre><code>public class GroupListFragment extends ListFragment implements LoaderManager.LoaderCallbacks&lt;Cursor&gt; {
  
  CursorAdapter mAdapter;
  private OnItemSelectedListener listener;
  private static final String[] PROJECTION ={GroupContract.GroupDetails.COLUMN_NAME_GROUP_NAME};
  private static final String SELECTION = null;
  final String[] FROM = {GroupContract.GroupDetails.COLUMN_NAME_GROUP_NAME};
  final int[] TO = {android.R.id.text1};
  private static final String[] ARGS = null;
  private static final String ORDER = null;
  private Cursor c;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_1,null,FROM,TO,0 );
      ReadDBAsync readDB = new ReadDBAsync();
      readDB.execute();
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState){
      super.onActivityCreated(savedInstanceState);
      setListAdapter(mAdapter);
      getLoaderManager().initLoader(0,null,this);
  }
  
  @Override
  public Loader&lt;Cursor&gt; onCreateLoader(int i, Bundle bundle) {
      Uri contenturi = Uri.parse("content://preamble.oneapp");
      Uri tableuri = Uri.withAppendedPath(contenturi,GroupContract.GroupDetails.TABLE_NAME);
      return new CursorLoader(getActivity(),tableuri,PROJECTION,SELECTION,ARGS,ORDER);
  }
  
  @Override
  public void onLoadFinished(Loader&lt;Cursor&gt; cursorLoader, Cursor cursor) {
      mAdapter.swapCursor(cursor);
  }
  
  @Override
  public void onLoaderReset(Loader&lt;Cursor&gt; cursorLoader) {
      mAdapter.swapCursor(null);
  }
  
  
  private class ReadDBAsync extends AsyncTask&lt;Void,Void,String&gt; {
  
      @Override
      protected String doInBackground(Void... voids) {
  
          ContractDBHelpers mDBHelper = new ContractDBHelpers(getActivity());
          SQLiteDatabase db = mDBHelper.getReadableDatabase();
          String returnvalue = "database read";
          c = db.query(GroupContract.GroupDetails.TABLE_NAME,PROJECTION,null,null,null,null,null);
          return returnvalue;
      }
  
      @Override
      protected void onPostExecute(String result){
          Toast.makeText(getActivity(), result, Toast.LENGTH_LONG).show();
      }
  }
  
  }
  </code></pre>