Layout For SQLite Resuts
<p>I'm trying to create a layout that looks like below for every row it returns from my database (will be last 7 days). Any help would be appreciated.</p>

<p>XML I created
            
        </p>

<pre><code>    &lt;QuickContactBadge
            android:id="@+id/image"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:scaleType="centerCrop"/&gt;

        &lt;TextView android:id="@+id/date"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_toRightOf="@+id/image"
                  android:gravity="center_vertical"
                  android:layout_alignParentRight="true"
                  android:layout_alignParentTop="true"
                  android:text="date"/&gt;

           &lt;TextView
               android:id="@+id/temp"
               android:layout_width="150dp"
               android:layout_height="wrap_content"
               android:layout_alignLeft="@+id/date"
               android:layout_below="@+id/date"
               android:gravity="center_vertical"
               android:text="temp" /&gt;

           &lt;TextView
                android:id="@+id/fertile"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_above="@+id/notes"
                android:layout_toRightOf="@+id/temp"
                android:gravity="center_vertical"
                android:text="fertile" /&gt;

            &lt;TextView
                android:id="@+id/notes"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/image"
                android:layout_alignLeft="@+id/temp"
                android:layout_below="@+id/temp"
                android:gravity="center_vertical"
                android:text="notes" /&gt;

    &lt;/RelativeLayout&gt;
</code></pre>

<p>Can someone show me how to loop through the sql to get the layout i desire?</p>

<pre><code>            public class HistoryFragment extends Fragment {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); 
        }       

         @Override
         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {



            View view = inflater.inflate(R.layout.fragment_history, container, false);

            //Get data from SQL
            SQLHelper entry = new SQLHelper(getActivity());
            entry.open();
            Cursor results = entry.getAllData();
            entry.close();



            return view;
         }

    }
</code></pre>

<p>SQL</p>

<pre><code>public class SQLHelper {
    //Database information
    private static final String DATABASE_NAME = "NFP";
    private static final int DATABASE_VERSION = 1;

    //Table Information
    private static final String DATABASE_TABLE = "charting";
    public static final String KEY_ROWID = "_id";
    public static final String KEY_NAME = "persons_name";
    public static final String KEY_CHARTING_DATE = "Date";
    public static final String KEY_CHARTING_TEMPERATURE = "temperature";
    public static final String KEY_CHARTING_STAMPS = "Stamps";
    public static final String KEY_CHARTING_FERTILE = "Fertile";
    public static final String KEY_CHARTING_NOTES = "Notes";
    public static final String KEY_CHARTING_PROC = "Proc";


    private DbHelper ourHelper;
    private final Context ourContext;
    private static SQLiteDatabase ourDatabase;

    private static class DbHelper extends SQLiteOpenHelper{
    public SQLHelper(Context c) {
        ourContext = c;
    }

            public DbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL( "CREATE TABLE " + DATABASE_TABLE + " (" +
                                        KEY_ROWID + " INTEGER  primary key AUTOINCREMENT, " +
                                        KEY_CHARTING_DATE + " TEXT primary key NOT NULL, " +
                                        KEY_NAME + " TEXT, " +
                                        KEY_CHARTING_TEMPERATURE + " INTEGER, " +
                                        KEY_CHARTING_STAMPS  + " INTEGER, " +
                                        KEY_CHARTING_FERTILE + " TEXT, " +
                                        KEY_CHARTING_NOTES + " TEXT, " +
                                        KEY_CHARTING_PROC +  " ); "
                    );
        }

    public SQLHelper open() throws SQLException{
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close(){
        ourHelper.close();
    }

    public long createEntry(String date, String temperature, String fertile, String notes) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_CHARTING_DATE, date);
        cv.put(KEY_CHARTING_TEMPERATURE, temperature);
        cv.put(KEY_CHARTING_FERTILE, fertile);
        cv.put(KEY_CHARTING_NOTES, notes);
        return ourDatabase.insertOrThrow (DATABASE_TABLE, null, cv);

    }

    public String getData() {
        String[] columns = new String[]{ KEY_CHARTING_DATE, KEY_CHARTING_TEMPERATURE, KEY_CHARTING_STAMPS, KEY_CHARTING_FERTILE, KEY_CHARTING_NOTES };
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);

        String result = "";

        int iDate = c.getColumnIndex(KEY_CHARTING_DATE);
        int iTemp = c.getColumnIndex(KEY_CHARTING_TEMPERATURE);
        int iStamps = c.getColumnIndex(KEY_CHARTING_STAMPS);
        int iFertile = c.getColumnIndex(KEY_CHARTING_FERTILE);
        int iNotes = c.getColumnIndex(KEY_CHARTING_NOTES);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            result = result + "" + c.getString(iDate) + "/n" + c.getString(iTemp) + "/n" + c.getString(iStamps) + "/n" + c.getString(iFertile) + "/n" + c.getString(iNotes) + "|";
        }

        return result;
    }
    public Cursor getAllData() {


        String[] columns = new String[]{ KEY_CHARTING_DATE, KEY_CHARTING_TEMPERATURE, KEY_CHARTING_STAMPS, KEY_CHARTING_FERTILE, KEY_CHARTING_NOTES };
        Cursor cursor = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);


        return cursor;
      }
}
</code></pre>
