title: Adding contacts to ListView
body: <p>I am developing an Android application. I am fetching all contacts one by one but i'm having trouble adding all contacts to the Listview</p>
  
  <pre><code>package com.jigar.Contact;
  
  import android.R.integer;
  import android.app.Activity;
  import android.app.ListActivity;
  import android.os.Bundle;
  
  
  import android.app.Activity;
  import android.content.ContentResolver;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.provider.ContactsContract;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.Toast;
  
  public class ContactStatus extends ListActivity 
  {
      /** Called when the activity is first created. */
      private  String contactid;
      private String name;
      private String hasphone;
      private String phonenumber;
      private String[] dat=new String[10];
      private int count=0;
      private ListView lv;
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          ContentResolver cr = getContentResolver();
          //lv=(ListView)findViewById(R.id.listv);
          Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI, null,null, null,null);
  
           while(cur.moveToNext())
           {
               contactid=cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
               name=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
               dat[count]=name;
               hasphone=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
               Toast.makeText(this, contactid, 1000).show();
               Toast.makeText(this, name, 1000).show();
              // dat[count]=name;
               count++;
               if(hasphone.equals("1"))
               {
                   hasphone="true";
               }
  
               if(Boolean.parseBoolean(hasphone))
               {
  
                   Cursor cphon=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"="+contactid, null, null);
                   while(cphon.moveToNext())
                   {
                       phonenumber=cphon.getString(cphon.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                       Toast.makeText(this, phonenumber, 1000).show();
                   }
  
               }
  
               //lv.setAdapter(new ArrayAdapter&lt;String&gt;(ContactStatus.this,android.R.layout.simple_list_item_1, dat)); 
           }
         //  ArrayAdapter arr=new ArrayAdapter(this,android.R.layout.simple_list_item_1, dat);
           //setListAdapter(arr);
      }
  }
  </code></pre>