Tôi đang cố thêm Chế độ xem vào bố cục tuyến tính theo chương trình.Android: Thêm hai chế độ xem văn bản theo chương trình
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);
}
Trước tiên, tôi chỉ thêm thông tin Xem và mọi thứ hoạt động tốt. Mông sau khi thêm cũng là dòng-Xem, nó bị lỗi với các lỗi sau đây:
java.lang.IllegalStateException: Con được chỉ định đã có một phụ huynh. Bạn phải gọi removeView() trên phụ huynh của đứa trẻ trước.
Vì vậy, tôi đã thử addView (Xem v, int index), nhưng nó đã bị lỗi với cùng một thông báo ...
Có ai đó là giải pháp không?
Cảm ơn, Martin