我正在使用TableLayout,我想动态创建多达50行 我的行有一个图像视图和文本视图,我在OnStart()方法中使用for循环创建50个动态行这是我的代码...,这样做的最佳做法是什么?任何人都可以告诉我这是最好的方法,或者你可以给我一个链接
public void onStart() {
{
//Items is Array list of 50 objects
TableLayout myTable= (TableLayout)findViewById(R.id.myTableLayout);
for (int i=0;i<Items.size();i++)
{
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
TextView rowText= new TextView(this);
rowText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
rowText.setText("dyanamic text");
ImageView rowImg = new ImageView(this);
rowImg.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
Bundle extras = getIntent().getExtras();
Drawable dra = Drawable.createFromPath(extras.getString("IconImagePath"));
rowImg.setImageDrawable(dra);
tableRow.addView(rowImg);
tableRow.addView(rowText);
myTable.addView(tableRow);
}
}
答案 0 :(得分:0)
如果您想要任何类似ListView的行为,请查看focusable row inside table android和WANTED: TableLayout-Like ListView