title: Get contacts by push of a button
body: <p>I want a scroll-able list of contacts to pop up when a click a button. I cannot figure out how to get it and how content resolvers, managed queries, and adapters work.</p>
  
  <p>I have tried with the following code:</p>
  
  <pre><code>package com.hapybay.rad;
  
  import android.app.Activity;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.ContactsContract;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  import android.database.Cursor;
  
  public class startingPoint extends Activity {
      Button redcandle;
      private ListView mContactList;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          /*Obtain handles to UI objects (Constructor)*/
          redcandle = (Button) findViewById(R.id.button1);
  
          /*Register handle for UI element*/
          redcandle.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  populateContactList();
              }
          });
      }
  
      private void populateContactList() {
          // Build adapter with contact entries
          Cursor cursor = getContacts();
          String[] fields = new String[] {
                  ContactsContract.Data.DISPLAY_NAME
          };
          SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry,   cursor,
                  fields, new int[]{R.id.contactEntryText});
          mContactList.setAdapter(adapter);
      }
  
      private Cursor getContacts()
      {
          // Run query
          Uri uri = ContactsContract.Contacts.CONTENT_URI;
          String[] projection = new String[] {
                  ContactsContract.Contacts.LOOKUP_KEY,
                  ContactsContract.Contacts.DISPLAY_NAME };
          String selection = null;
          String[] selectionArgs = null;
          String sortOrder = null;
  
          return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
      }
  }
  </code></pre>