How to dispaly result list into TableLayout row in android? How to dispaly result list into TableLayout row in android? sqlite sqlite

How to dispaly result list into TableLayout row in android?


try this way here I gave sample or demo code you have to modify as per your requirement and still have problem let me know

main layout

1. table.xml

<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/tableLayout"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:padding="5dp"    android:orientation="vertical"></TableLayout>

table row layout

2. table_item.xml

<?xml version="1.0" encoding="utf-8"?><TableRow xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="horizontal">    <TextView        android:layout_width="0dp"        android:layout_height="wrap_content"        android:id="@+id/history_display_no"        android:layout_weight="0.25"        android:gravity="center"/>    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/history_display_date"        android:layout_weight="0.25"        android:gravity="center"/>    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/history_display_orderid"        android:layout_weight="0.25"        android:gravity="center"/>    <TextView        android:layout_width="0dp"        android:layout_height="match_parent"        android:id="@+id/history_display_quantity"        android:layout_weight="0.25"        android:gravity="center"/></TableRow>

activity class

3. Activity

public class MyActivity extends Activity {    private TableLayout tableLayout;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.table);        tableLayout=(TableLayout)findViewById(R.id.tableLayout);        for (int i=0;i<5;i++){            View tableRow = LayoutInflater.from(this).inflate(R.layout.table_item,null,false);            TextView history_display_no  = (TextView) tableRow.findViewById(R.id.history_display_no);            TextView history_display_date  = (TextView) tableRow.findViewById(R.id.history_display_date);            TextView history_display_orderid  = (TextView) tableRow.findViewById(R.id.history_display_orderid);            TextView history_display_quantity  = (TextView) tableRow.findViewById(R.id.history_display_quantity);            history_display_no.setText(""+(i+1));            history_display_date.setText("2014-02-05");            history_display_orderid.setText("S0"+(i+1));            history_display_quantity.setText(""+(20+(i+1)));            tableLayout.addView(tableRow);        }    }}


check out context hierachy

for(IspHistoryListObject hl : historyList) {    count++;    TableRow tr = new TableRow(showRow.getContext());    LinearLayout ll = new LinearLayout(tr.getContext());    ll.setLayoutParams(new LinearLayout.LayoutParams(50,30));    TextView tv_sync_no = new TextView(ll.getContext());    TextView tv_sync_date = new TextView(ll.getContext());    TextView tv_sync_orderid = new TextView(ll.getContext());    TextView tv_sync_qty = new TextView(ll.getContext());    tv_sync_no.setText(String.valueOf(count));    tv_sync_date.setText(hl.getSyncDate().substring(0,10));    tv_sync_orderid.setText(hl.getSyncOrderIdRef());    tv_sync_qty.setText(String.valueOf(hl.getQty()));    ll.addView(tv_sync_no);    ll.addView(tv_sync_date);    ll.addView(tv_sync_orderid);    ll.addView(tv_sync_qty);    tr.addView(ll);    showRow.addView(tr);}


With listview you can easily do this:

ActivityMain.java

ListView lst = (ListView) findViewById(R.id.listView);View header = getLayoutInflater().inflate(R.layout.list_header, null);lst.addHeaderView(header);lst.setAdapter(new CustomerListAdapter(this,4));

list_header.xml is header layout