title: Populate ListView from SQLite database on android
body: <p>I have this database and I need to populate this <code>ListView</code> with the information.</p>
  
  <p>I already have a method on my DBHandler class which is:</p>
  
  <pre><code> public List&lt;Appointment&gt; getAppointments(){
              List&lt;Appointment&gt; appointmentList = new ArrayList&lt;Appointment&gt;();
              String selectQuery = "SELECT * FROM " + TABLE_APP;//query to search appointment by title
              SQLiteDatabase db = this.getWritableDatabase();
              Cursor cursor = db.rawQuery(selectQuery, null);
              if(cursor.moveToFirst()){
                  do{
                      Appointment appointment = new Appointment();
                      appointment.setID(Integer.parseInt(cursor.getString(0)));
                      appointment.setDate(cursor.getString(1));
                      appointment.setTitle(cursor.getString(2));
                      appointment.setTime(cursor.getString(3));
                      appointment.setDetails(cursor.getString(4));
  
                      appointmentList.add(appointment);
                  } while(cursor.moveToNext());
              }
  
              return appointmentList;
          }
  </code></pre>
  
  <p>And now I need to populate the list on my DeleteAppointment class:</p>
  
  <pre><code>   package com.example.calendar;
  
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  
  public class DeleteAppointment extends Activity implements OnClickListener{
  
      Appointment app;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.delete);
          Button delete = (Button)findViewById(R.id.btn_delete);
          Button deleteAll = (Button)findViewById(R.id.btn_deleteAll);
          ListView list = (ListView)findViewById(R.id.apptList);
          DBHandler db = new DBHandler(this);
          String[] columns = new String[]{app._date, app._title, app._time, app._details};
          int[] viewIDs = new int[]{R.id.date, R.id.name, R.id.time, R.id.details};
          Cursor cursor = (Cursor) db.getAppointments();
          SimpleCursorAdapter adapter;
          adapter = new SimpleCursorAdapter(getBaseContext(), R.layout.item, cursor, columns, viewIDs, 0);
          list.setAdapter(adapter);
          }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
          switch(v.getId()){
          case R.id.btn_delete:
              finish();
          break;
          }
  
      }
  
  }
  </code></pre>
  
  <p>And the xml file for the layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" &gt;
  
          &lt;ListView android:id="@+id/apptList"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;&lt;/ListView&gt;
  
          &lt;TableLayout 
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
              &lt;TableRow&gt;
  
                  &lt;Button
                      android:id="@+id/btn_delete"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="@string/deleteDialog"/&gt;
  
                  &lt;Button
                      android:id="@+id/btn_deleteAll"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="@string/deleteAll"/&gt;
  
              &lt;/TableRow&gt;
  
          &lt;/TableLayout&gt;
      &lt;/LinearLayout&gt;
  
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>The item layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;TextView
          android:id="@+id/date"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt;
  
      &lt;TextView
          android:id="@+id/time"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt;
  
      &lt;TextView
          android:id="@+id/name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt;
  
      &lt;TextView
          android:id="@+id/details"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And the Appointment class:</p>
  
  <pre><code>package com.example.calendar;
  
  import java.sql.Date;
  
  public class Appointment {
  
      //variables(that are the attributes of the database table)
      int _id;
      String _title;
      String _time;
      String _details;
      String _date;
  
      //empty constructor to add for the update method in the DBHandler
      public Appointment(){
  
      }
  
      public Appointment(int id, String date, String title, String time, String details){
  
          this._id = id;
          this._date = date;
          this._title = title;
          this._time = time;
          this._details = details;
  
      }
  
      public Appointment(String date, String title, String time, String details){
  
          this._date = date;
          this._title = title;
          this._time = time;
          this._details = details;
  
      }
  
      //----------GET/SET METHODS BELOW-----------
  
      //--------ID---------
  
      public int getID(){
          return this._id;
      }
  
      public void setID(int id){
          this._id = id;
      }
  
      //-------DATE-------
  
      public String getDate(){
          return this._date;
      }
  
      public void setDate(String date){
          this._date = date;
      }
  
      //-----TITLE---------
  
      public String getTitle(){
          return this._title;
      }
  
      public void setTitle(String title){
          this._title = title;
      }
  
      //------TIME-------
  
      public String getTime(){
          return this._time;
      }
  
      public void setTime(String time){
          this._time = time;
      }
  
      //------DETAILS--------
  
      public String getDetails(){
          return this._details;
      }
  
      public void setDetails(String details){
          this._details = details;
      }
  
  }
  </code></pre>
  
  <p>How can I populate this list in a simple way?</p>
  
  <p>Please help.</p>