Note that there are some explanatory texts on larger screens.

plurals
  1. POTextView string contents not visible when dynamically creating a tablelayout
    primarykey
    data
    text
    <p>I have been sitting over my head since couple of hours but I'm yet to find a solution to this strange issue. My requirement is that I need to dynamically create a table layout with header and contents. </p> <p>This is the code i use to generate the table layout dynamically.</p> <pre><code>TableLayout tableLayout = (TableLayout)findViewById(R.id.tabContentLayout); tableLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); tableLayout.removeAllViews(); for(int i=0;i&lt;rows.length;i++){ Log.d("Rows",rows[i]); String row = rows[i]; TableRow tableRow = new TableRow(getApplicationContext()); tableRow.setBackgroundResource(R.drawable.cell_shape); tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); final String[] cols = row.split(";"); Log.i(LOG_CLASS, "&lt;&lt;---- Columns count : " + cols.length + " ----&gt;&gt;"); for (int j = 0; j &lt; cols.length; j++) { final String col = cols[j]; TextView columsView = new TextView(getApplicationContext()); columsView.setBackgroundResource(R.drawable.cell_header); columsView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); columsView.setTextColor(color.white); columsView.setTextSize(TypedValue.COMPLEX_UNIT_SP,15); columsView.setGravity(Gravity.CENTER); columsView.setText(String.format("%7s", col)); Log.d("Cols", String.format("%7s", col)); tableRow.addView(columsView); } // tableLayout.addView(tableRow,new TableLayout.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT)); tableLayout.addView(tableRow); } tableLayout.requestLayout(); </code></pre> <p>Where the <strong>rows</strong> is a <code>String[]</code> containing entries delimited by <strong>;</strong></p> <p>For ex: <code>Apple;10/25/2013;10/25/2014;Srivatsa</code></p> <p>Latest Update : Infact the contents view is faintly visible on the <strong>emulator</strong>.(But this cannot be seen on a phone.) Now all i need is to get the text appear legible on the UI. </p> <p><img src="https://i.stack.imgur.com/YiujH.png" alt="Emulator - Screenshot"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload