Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am fetching data from database it contains multiple records now with this records i want to display them in the table layout format dynamically by using(foreach or anything)

Thanks in Advance
Posted
Comments
Richard MacCutchan 18-Dec-14 6:11am    
Raghu Golla 18-Dec-14 6:46am    
This is my design code what i had written:


<scrollview xmlns:android="http://schemas.android.com/apk/res/android"
="" android:id="@+id/scrl" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" android:removed="#3b5998">
<relativelayout
="" android:layout_width="fill_parent" android:layout_height="fill_parent">

<Button
android:id="@+id/btnview"
android:layout_width="40dp"
android:layout_height="30dp"
android:layout_alignBaseline="@+id/etxt_todate"
android:layout_alignBottom="@+id/etxt_todate"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:background="@drawable/custombutton"
android:text="GO"
android:textColor="#ff0000" />

<ImageView
android:id="@+id/test_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="22dp"
android:src="@drawable/logo" />

<edittext
android:id="@+id/etxt_fromdate"
="" android:layout_width="110dp" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/etxt_todate" android:layout_alignbottom="@+id/etxt_todate" android:layout_alignparentleft="true" android:layout_marginleft="16dp" android:removed="@drawable/customedit" android:ems="10" android:hint="FromDate">

<requestfocus>


<edittext
android:id="@+id/etxt_todate"
="" android:layout_width="110dp" android:layout_height="wrap_content" android:layout_below="@+id/test_image" android:layout_margintop="28dp" android:layout_toleftof="@+id/btnview" android:removed="@drawable/customedit" android:ems="10" android:hint="ToDate">

<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etxt_fromdate"
android:layout_below="@+id/btnview"
android:layout_marginTop="39dp" >

<TableRow
android:id="@+id/tbheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<textview
android:id="@+id/tbhcol1"
="" android:layout_weight="1" android:removed="#dcdcdc" android:gravity="center" android:padding="10dip" android:text="DATE" android:textcolor="#ff0000">

<textview
android:id="@+id/tbhcol2"
="" android:layout_weight="1" android:removed="#cac9c9" android:gravity="center" android:padding="10dip" android:text="BRANCH" android:textcolor="#ff0000">

<textview
android:id="@+id/tbhcol3"
="" android:layout_weight="1" android:removed="#dcdcdc" android:gravity="center" android:padding="10dip" android:text="QTY" android:textcolor="#ff0000">

<textview
android:id="@+id/tbhcol4"
="" android:layout_weight="1" android:removed="#cac9c9" android:gravity="center" android:padding="10dip" android:text="AMOUNT" android:textcolor="#ff0000">
</TableRow>

<TableRow
android:id="@+id/tbrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

Raghu Golla 18-Dec-14 6:46am    
And .java code is

protected void onPostExecute(List<salesdata> result)
{
super.onPostExecute(result);
if(pd!=null)
{
pd.dismiss();
if(result!=null)
{
for (SalesData salesData : result)
{
String date= salesData.getDate();
String branch=salesData.getBranch();
double qty=Double.parseDouble(salesData.getQty());
double net= Double.parseDouble(salesData.getNet());
tdate.setText(date);
tbranch.setText(branch);
tqty.setText(String.valueOf(qty));
tamount.setText(String.valueOf(net));
tbrow.addView(tdate);
tbrow.addView(tbranch);
tbrow.addView(tqty);
tbrow.addView(tamount);
}
tblout.addView(tbrow);
scrview.addView(tblout);
}
else
{
Toast.makeText(SalesSummary.this, "No data found", Toast.LENGTH_LONG).show();
}
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900