title: Howto show data from Array list to Custom ArrayAdapter
body: <p>I am working on an application in which i need to fetch all the contacts from the contact book and display. i want the user to select some contacts and add them in a group which is saved in db.</p>
  
  <p>i have created a custom list view- contactitem.xml-</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  
  
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"&gt;
  
  
   &lt;TextView
  
      android:id="@+id/contactname"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical"
      android:layout_weight="1"
      android:layout_marginLeft="20dp"
      android:ellipsize="end"        
     android:singleLine="true"
      android:clickable="true"/&gt;
  
   &lt;TextView
      android:id="@+id/contactnum"
      android:layout_width="wrap_content"
       android:textColor="@color/White"
       android:clickable="true"
       android:layout_gravity="center_vertical"
       android:layout_height="wrap_content"/&gt;
  
    &lt;Button
      android:id="@+id/add"
      android:layout_width="wrap_content"
      android:layout_height="35dp"
      android:text="@string/add_contacts"
      android:layout_gravity="center_vertical"
      android:layout_marginLeft="10dp"
      android:layout_marginRight="10dp"
      android:focusable="false"
      android:focusableInTouchMode="false"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>i have a SelectContact class for fetching contacts from Contact book-</p>
  
  <pre><code>public class SelectContacts extends Activity implementsOnItemClickListener {
  
      private List&lt;Contact&gt; list = new ArrayList&lt;Contact&gt;();
      private ListView contact_list;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.selectcontacts);
          contact_list=(ListView)findViewById(R.id.contactsListView);
          ContentResolver cr = getContentResolver();
          Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
          cur.moveToFirst();
          if (cur.getCount() &gt; 0) {
              while (cur.moveToNext()) {
                  String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                  String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                  if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) &gt; 0) {
                      Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
                      pCur.moveToFirst();
                      while (pCur.moveToNext()) {
                          String number=pCur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                          Contact c=new Contact();
                          c.setContactName(name);
                          c.setContactNum(number);
                          list.add(c);
                      }
                      pCur.close();
                  }
                  ContactAdapter contactAdapter=new ContactAdapter(this, R.layout.contactitem, list);
                  contact_list.setAdapter(contactAdapter);
              }
          }
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
              long arg3) {
          // TODO Auto-generated method stub
      }
  }
  </code></pre>
  
  <p>and implemented a custom adapter- ContactAdapter-</p>
  
  <pre><code>public class ContactAdapter extends ArrayAdapter&lt;Contact&gt;{
  
      List&lt;Contact&gt; items;
      LayoutInflater mInflater ; 
      Context context;
      int layoutResourceId; 
  
      public ContactAdapter(Context context, int layoutResourceId, List&lt;Contact&gt; items) {
          super(context, layoutResourceId, items);
          this.layoutResourceId=layoutResourceId;
          this.items = items;
          this.context=context;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          ViewHolder holder = new ViewHolder();
          if(row==null){
              mInflater = ((Activity)context).getLayoutInflater();
              row = mInflater.inflate(layoutResourceId, parent, false);
              holder.name = (TextView) row.findViewById(R.id.contactname);
              holder.number = (TextView) row.findViewById(R.id.contactnum);
              holder.add=(Button)row.findViewById(R.id.add);
              row.setTag(holder);
          }else{
              holder=(ViewHolder)row.getTag();
          }
  
          String name=items.get(position).getContactName();
          String number=items.get(position).getContactNum();
          holder.name.setText(name);
          holder.number.setText(number);
          holder.add.setText("Add");
          return row;
      }
  
      static class ViewHolder{
          TextView name;
          TextView number;
          Button add;
      }
  }
  </code></pre>
  
  <p>here Contact is a simple POJO-</p>
  
  <pre><code>public class Contact {
      private String contactName;
      private String contactNum;
  
      public String getContactName() {
          return contactName;
      }
      public void setContactName(String contactName) {
          this.contactName = contactName;
      }
  
      public String getContactNum() {
          return contactNum;
      }
      public void setContactNum(String contactNum) {
          this.contactNum = contactName;
      }
  
  }
  </code></pre>
  
  <p>i am a newbie in android.. </p>
  
  <p>Here when i start SelectContact activity it cannot display contact on the UI.. please help me guys...</p>
  
  <p>Thanks</p>