开发者

android best way to create dyanamic rows in TableLayout

i am working with TableLayout,i want to create up to 50 rows dynamically my row having one image view and text vie开发者_JAVA技巧w,i am creating 50 dynamic rows in OnStart() method by using for loop Here is My code..., is it best practice to do like this ? can any one tell me which is the best way to do this or can you refer me an links

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


If you want any ListView-like behavior, take a look at focusable row inside table android and WANTED: TableLayout-Like ListView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜