Android: agregue dos vistas de texto mediante programación
Estoy tratando de agregar Vistas a un diseño lineal mediante programación.
LinearLayout layout = (LinearLayout) findViewById(R.id.info);
String [] informations = topOffer.getInformations();
TextView informationView;
View line = new View(this);
line.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT));
line.setBackgroundColor(R.color.solid_history_grey);
for (int i = 0; i < informations.length; i++) {
informationView = new TextView(this);
informationView.setText(informations[i]);
layout.addView(informationView, 0);
layout.addView(line, 1);
}
Primero, solo agregué informationsView, y todo funcionó bien. Butt después de agregar también la vista de línea, se bloqueó con el siguiente error:
java.lang.IllegalStateException: el elemento secundario especificado ya tiene un elemento primario. Primero debe llamar a removeView () en el padre del niño.
Así que probé addView (View v, int index), pero se bloqueó con el mismo mensaje ...
¿Alguien tiene una solución?
Gracias martin