Code example for TableRow

Methods: addView, setBackgroundColor, setLayoutParams

0
		 
        // Go through each item in the array 
        for (int i = 0; i < dataArray.length; i++)
        { 
            // Create a TableRow and give it an ID 
            TableRow tr = new TableRow(this);
             
            tr.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));   
             
            tr.setBackgroundColor(Color.WHITE);
             
            // Create a TextView to house the name of the province 
            TextView text = new TextView(this);
            text.setText(dataArray[i]);
            text.setTextColor(Color.BLACK);
            text.setBackgroundColor(Color.WHITE);
            tr.addView(text);
 
            // Add the TableRow to the TableLayout 
            tl.addView(tr, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));