title: How do I make my checkbox checked by default in my custom adapter?
body: <p>In my custom adapter I have an array list of phone numbers, <code>checkedContactsAsArrayList</code>, which I get from my <code>php</code>. In my Android App it looks something like this:</p>
  
  <pre><code>[+12345,+23456,+34567]
  </code></pre>
  
  <p>I make a string, <code>contactToCheck</code>, from each value of <code>checkedContactsAsArrayList</code>, with :</p>
  
  <pre><code>for (int i = 0; i &lt; checkedContactsAsArrayList.size(); i++) {
      contactToCheck = checkedContactsAsArrayList.get(i);
  
                                  }
  </code></pre>
  
  <p>The values of <code>contactToCheck</code> will always be present in another array list, <code>MatchingContactsAsArrayList</code>.</p>
  
  <p>For example, <code>MatchingContactsAsArrayList</code> might look like this:</p>
  
  <pre><code>[+12345,+23456,+34567,+45678,+56789,+01234]
  </code></pre>
  
  <p>A <code>checkbox</code> loads in all cells of my <code>Listview</code> beside these phone numbers, but for the <code>contactToCheck</code> numbers I want the checkbox to be ticked/ checked by default.</p>
  
  <p>Can you tell me what I need to put into my </p>
  
  <pre><code>        if (MatchingContactsAsArrayList.contains(contactToCheck))
          {
  
      }
  </code></pre>
  
  <p>for this to happen?</p>
  
  <p>Here is my <code>getView</code> code:</p>
  
  <pre><code> @Override
      public View getView(int i, View convertView, ViewGroup viewGroup) {
          System.out.println("getView number is :" + i + "convertView is : " + convertView);
  
          ViewHolder viewHolder = null;
  
          if (convertView == null) {
  
              //if there is nothing there (if it's null) inflate the view with the layout
              LayoutInflater li = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = li.inflate(R.layout.phone_inflate_listview, null);
  
              viewHolder = new ViewHolder();
              //      So, for example, title is cast to the name id, in phone_inflate_listview,
              //      phone is cast to the id called no etc
              viewHolder.title = (TextView) convertView.findViewById(R.id.name);
              viewHolder.phone = (TextView) convertView.findViewById(R.id.no);
              viewHolder.invite = (Button)  convertView.findViewById(R.id.btnInvite);
              viewHolder.check = (CheckBox) convertView.findViewById(R.id.checkBoxContact);
  
              //remember the state of the checkbox
              viewHolder.check.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) _c);
  
              convertView.setTag(viewHolder);
  
          } else {
  
              viewHolder = (ViewHolder) convertView.getTag();
  
          }
  //        store the holder with the view
          final SelectPhoneContact data = (SelectPhoneContact) arraylist.get(i);
          //in the listview for contacts, set the name
          viewHolder.title.setText(data.getName());
          //in the listview for contacts, set the number
          viewHolder.phone.setText(data.getPhone());
  
          ////*********************
  
          //for every phone number in the MatchingContactsAsArrayList array list...
          for (int number = 0; number &lt; MatchingContactsAsArrayList.size(); number++) {
  
                  if (MatchingContactsAsArrayList.contains(contactToCheck))
                  {
  
  
              }
  
          }
  
  
          viewHolder.check.setChecked(data.isSelected());
  
  
  
          viewHolder.check.setTag(data);
  
          // Return the completed view to render on screen
  
          return convertView;
  
      }
  </code></pre>