Androidアプリ開発初心者です。テーブルに複数の行を作成する方法と、行を作成するための主要なパフォーマンスを教えてください。これで 3 つの行を作成できます。しかし、テーブルにデータを入力しながら行を自動生成したい。
1 に答える
0
これを試して:
//Declare mytable in layout XML file.
TableLayout tl = (TableLayout) findViewById(R.id.mytable);
//loop through number of times u want to create row.
for (int current = 0; current < numofrowsrequired; current++)
{
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
tr.setId(100+current);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
//add required views with required parameters
TextView labelTV = new TextView(this);
labelTV.setId(200+current);
labelTV.setText(provinces[current]);
labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
于 2013-02-06T04:44:29.130 に答える