title: Custom ArrayAdapter with data from SQLite local db
body: <p>I am doing a project where I want to display a list of contacts names in a ListView. The names are retrieved from the local sqli db. So far I have managed to retrieve the names and display them using the standard ArrayAdapter class.</p>
  
  <p>However for more control I am trying to create my own adapter to allow me to also display control buttons on each row. I am confused about this piece of code:</p>
  
  <pre><code>private void fillData() {
      Cursor mContactsCursor = mDbAdapter.getAllContacts();
      startManagingCursor(mContactsCursor);
  
      String [] from = new String[] {ContactsDbAdapter.COLUMN_FNAME, ContactsDbAdapter.COLUMN_LNAME};
      int [] to = new int [] { R.id.fname, R.id.lname};
  
  
      //What variables should constructor take? 
      adapter = new ContactsListAdapter(this, from, to);
  
      data.setAdapter(adapter);
  
  }
  </code></pre>
  
  <p>Basically I don't know how to pass these values to the constructor or if I should even do that??</p>
  
  <pre><code>String [] from = new String[] {ContactsDbAdapter.COLUMN_FNAME,   ContactsDbAdapter.COLUMN_LNAME};
      int [] to = new int [] { R.id.fname, R.id.lname};
  </code></pre>
  
  <p>This is my ContactsListAdapter class:</p>
  
  <pre><code>public class ContactsListAdapter extends ArrayAdapter&lt;Contact&gt; {
  
  private List&lt;Contact&gt; contacts;
  private Button deleteBtn;
  private Button editBtn;
  private TextView name;
  
  public ContactsListAdapter(Context context,List&lt;Contact&gt; contacts) {
      super(context, R.layout.contact_row, contacts);
      this.contacts = contacts;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      View v = convertView;
  
      if(v == null){
          LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = vi.inflate(R.layout.contact_row, null);
      }
  
      //assign values to the view
      final Contact c = this.contacts.get(position);
  
      //add listeners to buttons
      deleteBtn = (Button)v.findViewById(R.id.deleteBtn);
      deleteBtn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Toast.makeText(v.getContext(), "Deleted", Toast.LENGTH_SHORT).show();
          }
      });
  
      editBtn = (Button)v.findViewById(R.id.editBtn);
      editBtn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Toast.makeText(v.getContext(), "Edit", Toast.LENGTH_SHORT).show();
          }
      });
  
  
      //insert name into the text view
      name = (TextView)v.findViewById(R.id.name);
      name.setText(c.getName());
  
      return v;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The code for this class was taken from an example where I used a custom list adapter which was getting data from a hard coded array so I probably am missing something when it comes to getting data from the db.</p>
  
  <p>Any advice is much appreciated. Many thanks.</p>