TextView name = (TextView) findViewById(R.id.addName); LinearLayout layout = (LinearLayout) findViewById(R.id.addLayout); Cursor cursor1 = db.rawQuery(queryText, null); cursor1.moveToFirst(); for (int i = 0; i < cursor1.getColumnCount(); i++) { TextView nameCol = new TextView(this); EditText inner = new EditText(this); nameCol.setText(" " + cursor1.getColumnName(i) + ": "); nameCol.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); nameCol.setTextSize(23); nameCol.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(nameCol); inner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(inner,i); } cursor1.close(); According to the code, H must be added to the TextView and EditText pairs, but first all TextViews are added, and then all the EditTexts.