title: How to use two Cursors and CursorJoiner in LoaderManager in android
body: <p>I have a <strong><code>ContentProvider</code></strong>, it's having two tables 1. <strong><code>OnlineContacts</code></strong> 2. <strong><code>AllContacts</code></strong>. Then i have a method in which i am querying both the tables and getting their resultant <code>cursors</code> separately. And then <strong>joining</strong> them using <strong><code>CursorJoiner</code></strong> and making a list of <strong><code>Contacts</code></strong>. Passing this list to my <strong><code>CustomAdapter extending BaseAdapter</code></strong>, i am populating my <code>listview</code>. Like : </p>
  
  <pre><code>public static List&lt;Contact&gt; getContacts(Context context){
      List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;(); 
  
  // Getting First Cursor
      String URL = xyz;
      Uri baseUri1 = Uri.parse(URL);
      String[] select = xyz; 
      String where =xyz; 
      Cursor cursor =  context.getContentResolver().query(baseUri1, select, where, null, "pid");
  
  // Getting 2nd Cursor
      Uri baseUri = xyz; 
      String[] projection =xyz; 
      String selection =xyz; 
      String[] selectionArgs = null;
      String sortOrder = xyz; 
  
      Cursor mCursor= context.getContentResolver().query(baseUri, projection, selection, selectionArgs, sortOrder);
  
      // Joinging Both Cursors
  
      CursorJoiner joiner = new CursorJoiner(cursor, new String[] {MyContentProvider.PHONE_ID} , mCursor, new String[] {MyContentProvider.Phone._ID});
      for (CursorJoiner.Result joinerResult : joiner) {
          Contact cont = new Contact();
  
          switch (joinerResult) {
          case LEFT:
              // handle case where a row in cursorA is unique
              break;
          case RIGHT:
              // handle case where a row in cursorB is unique
  
          case BOTH:
              // handle case where a row with the same key is in both cursors
              cont.setID(xyz);
              cont.setName(xyz);
              cont.setPhoneNumber(xyz);
              cont.setStatus("0");
              contactList.add(cont);
              break;
          }
      }
      mCursor.close();
      cursor.close();
      return contactList;
  }   
  </code></pre>
  
  <p>And here is my <strong>CustomAdapter</strong> : </p>
  
  <pre><code>private class CustomAdapter extends BaseAdapter {
  
          List&lt;Contact&gt; contactsList ;
          public CustomAdapter(List&lt;Contact&gt; contactsList){
              this.contactsList = contactsList;
          }
  
          public List&lt;Contact&gt; contacts() {
              return this.contactsList;    
          }
  
          @Override
          public int getCount() {
              return contactsList.size();
          }
  
          @Override
          public Contact getItem(int arg0) {
              return contactsList.get(arg0);
          }
  
          @Override
          public long getItemId(int arg0) {
              return arg0;
          }
  
          @Override
          public View getView(int position, View view, ViewGroup viewGroup) {
  
              SimpleViewHolder viewHolder;
              if(view==null)
              {
                  LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  view = inflater.inflate(R.layout.list_item, viewGroup,false);
                  viewHolder = new SimpleViewHolder(view);
                  view.setTag(viewHolder);
              }
  
              viewHolder = (SimpleViewHolder) view.getTag();
  
              TextView contName = (TextView) viewHolder.get(R.id.nameText);
              ImageView image = (ImageView) viewHolder.get(R.id.contact_image);
  
              Contact contact = contactsList.get(position);
              image.setBackgroundResource(R.drawable.person_empty_offline);
  
              contName.setText(contact.getName());
              return view;
          }
  
      }   
  </code></pre>
  
  <p>Now , i need to do it using <strong><code>LoaderManager</code></strong>. I know , to some extent, the implementation of it. I know , the <strong><code>onCreateLoader</code></strong> acts like:</p>
  
  <pre><code>    public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) {
  
          Uri baseUri = xyz;
          String[] projection =  xyz;
          String selection =  xyz;
          String[] selectionArgs = null;
          String sortOrder =  xyz;
          return  new CursorLoader(getActivity(), baseUri, projection, selection, selectionArgs, sortOrder);
  }
  </code></pre>
  
  <p>And in <code>OnCreate</code> , if i use <strong><code>MyCursorAdapter extending CursorAdapter</code></strong>, we do something like : </p>
  
  <pre><code>mAdapter = new MyCursorAdapter(getActivity(), null, 0);
          setListAdapter(mAdapter);
          getLoaderManager().initLoader(0, null, this);
  </code></pre>
  
  <p>Now, i need to do is how can i achive the above implementation using <strong><code>LoaderManager</code></strong>. I didn't know how to ask thats why its too explanatory. </p>