简体   繁体   中英

How to make Table with Multiple coloumn and rows are added dynamicaly

I want to create a table in android with multiple column. I want 3-4 columns and I should be able to add the rows dynamically in the table. Can anybody provide me a sample code for this. I have tried by using the Base Adapter and List view But problem is that when I moving the List view Horizontal fix column will not move properly. It moves but fraction of delay. I dont know how to do above and from last one weak I am searching on this can any body please help me on this. If you want I can explain more briefly.

As you say you have to make 3-4 columns and multiple rows so why you want to use tableview or Listview.You have to use gridview .Gridview provide you mechanism for multiple columns and rows.

Grid view

If you don't want to use gridview then you can create a row in xml that has 3-4 columns and then you can inflate that row and you can add that row into the tableview.

Layout Inflater

TableLayout tl = (TableLayout)findViewById(R.id.TableLayout01);

TableRow tr = new TableRow(this);
tr.setId(100);
tr.setOrientation(TableRow.VERTICAL);

TextView textvw01 = new TextView(this);
textvw01.setId(200);
textvw01.setText("blah");
tr.addView(textvw01);

TextView textvw02 = new TextView(this);
textvw02.setId(300);
textvw02.setText("Blah2");
tr.addView(textvw02);

/* Add row to TableLayout. */
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

Try it out,may work for u

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM