Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd TextViews programmatically
    primarykey
    data
    text
    <p>I have an empty <code>LinearLayout</code>, and I need to add a dynamic number of <code>TextView</code>s to it. However when I use the code below, only the first <code>TextView</code> is shown:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] listofnumbers = new String[1000]; for ( int i = 0 ; i &lt; 1000 ; ++i ) { listofnumbers[i] = "null"; } Context context = getBaseContext(); String text = null; Uri uri = Uri.parse("content://sms"); Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); String[] columnNames = cursor.getColumnNames(); LinearLayout lv = new LinearLayout(context); LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, dip(48)); boolean v = true; while (cursor.moveToNext()) { String numberString = (cursor.getString( cursor.getColumnIndexOrThrow("address") ) ).replace(" ", ""); int i = 0; boolean numberNotPresent = true; for ( ; listofnumbers[i] != "null" ; ++i ) { if ( numberString.equals(listofnumbers[i]) ) { numberNotPresent = false; } } if ( numberNotPresent == true ) { text = (CharSequence) "From: " + cursor.getString(cursor.getColumnIndexOrThrow("address")) + ": " + cursor.getString(cursor.getColumnIndexOrThrow("body")); listofnumbers[i] = numberString; TextView tv = new TextView(this); tv.setText(text); tv.setLayoutParams(textViewParams); lv.addView( tv ); } } setContentView(lv); } </code></pre> <p>Where have I gone wrong? </p>
    singulars
    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