How to create a table with dynamic rows in Android
I am new at android, I am stuck with the following puzzle.
I need to create a table in Android which looks the following:
Category | Item Name | Marks Obtained | Max Marks|
Row 1 information
Row2 information
The problem that I am facing is that these rows need to be created on the fly depending on the number of items.
I have looked around and found table layout information which is very generic or does not show how to 开发者_如何学JAVAcreate dynamic tables.P.S. I cannot attach the exact picture of the table because I don't have enough points
you create this. First create a table. Now you came to know the number of rows that you want to create(dynamically).
private TableLayout myTableLay;
private TableRow demoTableRow[];
private String cat[],itemName[],marks[],maxMarks[];
private int count;
public void example()
{
myTableLay = new TableLayout(this);
myTableLay.removeAllViews();
myTableLay.refreshDrawableState();
// i hope now you got count.
demoTableRow = new TableRow[count];
cat = new String[count];
itemName= new String[count];
marks= new String[count];
maxMarks= new String[count];
for(int i=0;i<count;i++)
{
// add all inforamation to your tablerow in such a maaner that you want to display on screen.
myTableLay.addView(demoTableRow[i);
}
//hope it might helpful.
}
精彩评论