Search code examples
androidandroid-layoutandroid-tablelayout

Table Layout and Table Row


I need to create six textview dynamically in but one condition each table row have only three textview for mine i need to place two table row and place three textview each please


Solution

  • Try something like this.

        TableLayout myTable=new TableLayout(this);        
        TextView[][] myTextView=new TextView[3][3];
        myTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
        TableRow[] myRow=new TableRow[3];        
        for (int i = 0; i < 3; i++) {
            myRow[i]=new TableRow(this);
            myRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));           
            for (int j = 0; j < 3; j++) {               
                myTextView[i][j]=new TextView(this);  
                myTextView[i][j].setText("Your Text");
                myRow[i].addView(myTextView[i][j]);
            }   
            myTable.addView(myRow[i]);
        }
        LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
        lin.addView(myTable);