Populating listview with sqlite db
<p>I'm trying to populate a listview with a sqlite database, so far I think I've properly created/added items to the database. I'm not sure how to get those items and put them in my list view.</p>

<p>Here is my database creation(RecordsDatabase.java):</p>

<pre><code>public class RecordsDatabase extends SQLiteOpenHelper {

public static final int DATABASE_VERSION = 1;

public RecordsDatabase(Context context) {
    super(context, RecordContract.RecordInfo.DATABASE_NAME, null, DATABASE_VERSION);
    Log.d("Database operations", "Database created");
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + RecordContract.RecordInfo.TABLE_NAME + " ("
                    + RecordContract.RecordInfo.RECORDS_DATE + " TEXT NOT NULL,"
            + RecordContract.RecordInfo.RECORDS_SQUAT + " TEXT NOT NULL,"
            + RecordContract.RecordInfo.RECORDS_BENCH + " TEXT NOT NULL,"
            + RecordContract.RecordInfo.RECORDS_DEAD + " TEXT NOT NULL,"
            + RecordContract.RecordInfo.RECORDS_TOTAL + " TEXT NOT NULL)"

    );
    Log.d("Database operations", "Table created");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

public void putInformation(RecordsDatabase rdb, String date, String squat, String bench, String dead, String total) {
    SQLiteDatabase SQ = rdb.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(RecordContract.RecordInfo.RECORDS_DATE, date);
    contentValues.put(RecordContract.RecordInfo.RECORDS_SQUAT, squat);
    contentValues.put(RecordContract.RecordInfo.RECORDS_BENCH, bench);
    contentValues.put(RecordContract.RecordInfo.RECORDS_DEAD, dead);
    contentValues.put(RecordContract.RecordInfo.RECORDS_TOTAL, total);
    long k = SQ.insert(RecordContract.RecordInfo.TABLE_NAME, null, contentValues);
    Log.d("Database operations", "Record added(1 row)");

}

public Cursor getRecords(RecordsDatabase rdb) {
    SQLiteDatabase SQ = rdb.getReadableDatabase();
    String[] columns = {RecordContract.RecordInfo.RECORDS_DATE, RecordContract.RecordInfo.RECORDS_SQUAT, RecordContract.RecordInfo.RECORDS_BENCH
    , RecordContract.RecordInfo.RECORDS_DEAD, RecordContract.RecordInfo.RECORDS_TOTAL};
    Cursor CR = SQ.query(RecordContract.RecordInfo.TABLE_NAME, columns,null, null, null, null, null);
    return CR;

}
</code></pre>

<p>This is where I add buttons on button click(MyMaxes.java):</p>

<pre><code> mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0);
            SharedPreferences.Editor editor = pref.edit();
                if (mEditTextBench.getText().length() &gt; 0 &amp;&amp; mEditTextDead.getText().length() &gt; 0 &amp;&amp; mEditTextSquat.getText().length() &gt; 0) {
                maxBenchDB = mEditTextBench.getText().toString();
                maxSquatDB = mEditTextSquat.getText().toString();
                maxDeadDB = mEditTextDead.getText().toString();
                maxTotalDB = mTxtTotal.getText().toString();

                DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                Date today = Calendar.getInstance().getTime();
                reportDate = df.format(today);

                RecordsDatabase DB = new RecordsDatabase(mContext);
                DB.putInformation(DB, reportDate, maxSquatDB, maxDeadDB, maxBenchDB, maxTotalDB);
                Toast.makeText(getBaseContext(), "added", Toast.LENGTH_LONG).show();
</code></pre>

<p>Here is where I have my listview that I want to populate using the sqlite db and my custom.xml(MyProgress.java):</p>

<pre><code>public class MyProgress extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_progress);
    mToolBar = activateToolbar();
    setUpNavigationDrawer();
    getSupportActionBar().setTitle("My Progress");

    ListView listViewRec = (ListView) findViewById(R.id.listViewRecord);
</code></pre>

<p>And heres my custom_record.xml:</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;

&lt;TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Date"
    android:textSize="18sp"
    android:id="@+id/txtDate"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/&gt;

&lt;TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Bench"
    android:id="@+id/txtBench"
    android:paddingRight="5dp"
    android:textSize="18sp"
    android:layout_gravity="center_horizontal"
    android:layout_alignParentTop="true"
    android:paddingLeft="5dp"
    android:layout_toLeftOf="@+id/txtSquat"
    android:layout_toStartOf="@+id/txtSquat"/&gt;

&lt;TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Squat"
    android:textSize="18sp"
    android:paddingRight="5dp"
    android:id="@+id/txtSquat"
    android:layout_alignParentTop="true"
    android:paddingLeft="5dp"
    android:layout_toLeftOf="@+id/txtDead"
    android:layout_toStartOf="@+id/txtDead"
    /&gt;

&lt;TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Dead"
    android:paddingRight="5dp"
    android:textSize="18sp"
    android:id="@+id/txtDead"
    android:layout_alignParentTop="true"
    android:paddingLeft="5dp"
    android:layout_toLeftOf="@+id/txtTotal"
    android:layout_toStartOf="@+id/txtTotal"/&gt;

&lt;TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Total"
    android:textSize="18sp"
    android:paddingRight="5dp"
    android:paddingLeft="5dp"
    android:id="@+id/txtTotal"
    android:layout_marginRight="34dp"
    android:layout_marginEnd="34dp"

    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"/&gt;
</code></pre>

<p></p>

<p>And here is my CursorAdapter so far:</p>

<pre><code>public class TodoCursorAdapter extends CursorAdapter {

  public TodoCursorAdapter(Context context, Cursor c, int flags) {
          super(context, c, flags);
  }

  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
          return LayoutInflater.from(context).inflate(R.layout.custom_record, parent, false);
  }

  @Override
  public void bindView(View view, Context context, Cursor cursor) {
          TextView txtDate = (TextView) view.findViewById(R.id.txtDate);
          TextView txtSquat = (TextView) view.findViewById(R.id.txtSquat);
          TextView txtBench = (TextView) view.findViewById(R.id.txtBench);
          TextView txtDead = (TextView) view.findViewById(R.id.txtDead);
          TextView txtTotal = (TextView) view.findViewById(R.id.txtTotal);

          String date = cursor.getString(cursor.getColumnIndexOrThrow("date"));
          String squat = cursor.getString(cursor.getColumnIndexOrThrow("squat"));
          String bench = cursor.getString(cursor.getColumnIndexOrThrow("bench"));
          String dead = cursor.getString(cursor.getColumnIndexOrThrow("dead"));
          String total = cursor.getString(cursor.getColumnIndexOrThrow("total"));

          txtBench.setText(bench);
          txtDate.setText(date);
          txtDead.setText(dead);
          txtSquat.setText(squat);
          txtTotal.setText(total);
  }
}
</code></pre>

<p>I'm not sure how I would go about getting the listview to populate using the sqlite db.. I think I am adding items to the db the correct way though. Thanks for any help!</p>