0

i am working with TableLayout,i want to create up to 50 rows dynamically my row having one image view and text view,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);
     }
}
Bad Boy
  • 628
  • 2
  • 5
  • 23

1 Answers1

0

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

Community
  • 1
  • 1
Thane Anthem
  • 4,093
  • 4
  • 26
  • 24