2011-04-26 64 views
0

我正在使用TableLayout,我想動態創建多達50行 我的行有一個圖像視圖和文本視圖,我在OnStart()方法中創建了50個動態行通過使用for循環這是我的代碼...,這是最好的做法嗎?任何一個可以告訴我這是做到這一點的最好辦法,或者你可以參考我的鏈接android在TableLayout中創建浮動行的最佳方式

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); 
    } 
} 

回答

相關問題