title: Display data from sqlite in Table layout,
body: <p>i want to display my data from sqlite to my table which i create using tablelayout using xml, how i want to do that? is there any example? i do not know how to pass the value into table.. is it the same as we do listview or textview?</p>
  
  <p>below is my xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:textColor="#fcfafa" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="14dp"
          android:text="@string/glucose"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:textColor="#030303" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout1"
          android:layout_width="500dp"
          android:layout_height="15dp"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView1"
          android:layout_marginTop="17dp"
          android:background="#C4BFBF"
          android:orientation="vertical" &gt;
      &lt;/LinearLayout&gt;
  
      &lt;ImageButton
          android:id="@+id/imageButton1"
          android:layout_width="28dp"
          android:layout_height="28dp"
          android:layout_alignParentLeft="true"
          android:layout_alignTop="@+id/textView1"
          android:layout_marginLeft="16dp"
          android:contentDescription="@string/btn_home"
          android:onClick="onClickHome"
          android:src="@drawable/homebtn" /&gt;
  
      &lt;Button
          android:id="@+id/imageButton2"
          android:layout_width="60dp"
          android:layout_height="35dp"
          android:layout_alignParentRight="true"
          android:layout_below="@+id/linearLayout1"
          android:layout_marginRight="18dp"
          android:layout_marginTop="10dp"
          android:onClick="onClickAdd"
          android:textSize="14sp"
          android:text="@string/btn_add"/&gt;
  
      &lt;TableLayout
          android:id="@+id/myTableLayout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="1dp"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_below="@+id/imageButton2"
          android:layout_marginTop="5dp" &gt;
  
          &lt;TableRow
              android:id="@+id/tableRow1"
              android:layout_width="wrap_content"
              android:layout_height="100dp" 
              android:background="@drawable/cell_normalshape"&gt;
  
              &lt;TextView
                  android:id="@+id/textView2"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="55dp"
                  android:text="@string/date"
                  android:gravity="center_horizontal"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"
                  android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView3"
                  android:background="@drawable/cell_normalshape"
                  android:layout_weight="0.2"
                  android:text="@string/Breakfast"
                  android:layout_span="2"
                  android:gravity="center_horizontal"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"/&gt;
  
              &lt;TextView
                  android:id="@+id/textView4"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="70dp"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"
                  android:gravity="center_horizontal"
                  android:layout_span="2"
                  android:text="@string/Lunch"
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView5"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="70dp"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"
                  android:layout_span="2"
                  android:gravity="center_horizontal"
                  android:text="@string/Dinner"
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
          &lt;/TableRow&gt;
          &lt;TableRow
              android:id="@+id/tableRow2"
              android:layout_width="wrap_content"
              android:layout_height="100dp" 
              android:background="@drawable/cell_normalshape"&gt;
  
           &lt;TextView
                  android:id="@+id/textView7"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="40dp"
                  android:textColor="#2A0A0A"
                  android:text=""
                  android:textSize="18sp"
                  android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView8"
                  android:background="@drawable/cell_normalshape"
                  android:layout_weight="0.3"
                  android:text="@string/Pre"
                  android:gravity="center_horizontal"
                  android:layout_width="wrap_content"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"/&gt;
  
              &lt;TextView
                  android:id="@+id/textView9"
                  android:background="@drawable/cell_normalshape"
                  android:layout_weight="0.3"
                  android:layout_width="wrap_content"
                  android:textColor="#2A0A0A"
                  android:gravity="center_horizontal"
                  android:textSize="16sp"
                  android:text="@string/Post"
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView10"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="30dp"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"
                  android:text="@string/Pre"
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView11"
                  android:layout_width="40dp"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"
                  android:text="@string/Post"
                  android:gravity="center_horizontal"
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView12"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="30dp"
                  android:text="@string/Pre"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"/&gt;
  
              &lt;TextView
                  android:id="@+id/textView13"
                  android:background="@drawable/cell_normalshape"
                  android:text="@string/Post"
                  android:layout_width="40dp"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="16sp"/&gt;
          &lt;/TableRow&gt;
  
          &lt;TableRow
              android:id="@+id/tableRow3"
              android:layout_width="wrap_content"
              android:layout_height="100dp" 
              android:background="@drawable/cell_normalshape"&gt;
  
              &lt;TextView
                  android:id="@+id/textView15"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="40dp"
                  android:textColor="#2A0A0A"
                  android:text=""
                  android:textSize="18sp"
                  android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView16"
                  android:background="@drawable/cell_normalshape"
                  android:layout_weight="0.3"
                  android:text=""
                  android:layout_width="wrap_content"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="18sp" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView17"
                  android:background="@drawable/cell_normalshape"
                  android:layout_weight="0.3"
                  android:layout_width="wrap_content"
                  android:textColor="#2A0A0A"
                  android:textSize="18sp"
                  android:text=""
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView18"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="30dp"
                  android:textColor="#2A0A0A"
                  android:textSize="18sp"
                  android:text=""
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView19"
                  android:layout_width="40dp"
                  android:textColor="#2A0A0A"
                  android:textSize="18sp"
                  android:text=""
                  android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView20"
                  android:background="@drawable/cell_normalshape"
                  android:layout_width="30dp"
                  android:text=""
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="18sp" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView21"
                  android:background="@drawable/cell_normalshape"
                  android:text=""
                  android:layout_width="40dp"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:textColor="#2A0A0A"
                  android:textSize="18sp" /&gt;
          &lt;/TableRow&gt;
      &lt;/TableLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and here is my code..</p>
  
  <pre><code>private SQLiteDatabase database;
  private ArrayList&lt;String&gt; result = new ArrayList&lt;String&gt;(); 
  private ArrayList&lt;Long&gt; idList = new ArrayList&lt;Long&gt;();
  private ArrayAdapter&lt;String&gt; adapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.glucose_view);
      TableLayout myTable = (TableLayout)findViewById(R.id.myTableLayout);
  
      DBHelper helper = new DBHelper(this);
      database = helper.getWritableDatabase();
  
      // view data
  
      try{
          String query = "select * from " + DBHelper.TABLE_GLUCOSE;
  
          Cursor c = database.rawQuery(query, null);
  
          c.moveToFirst();
          c.moveToPosition(3);  // may be two, not sure if the cursor starts at 0 or 1
          while (c.isAfterLast() == false) {
              String tblName = c.getString(1);
              Cursor table = database.rawQuery("SELECT * FROM " + DBHelper.TABLE_GLUCOSE,null);
              table.moveToFirst();
              if (table.getString(table.getColumnIndex("Title")) != null) {
                  //  Your code to create table
              }
              c.moveToNext();
          }
  }
  </code></pre>
  
  <p>can anyone help me..</p>