Tôi có Hoạt động hiển thị nhận xét. Các bình luận có một bố trí, vì vậy tôi không thể chỉ sử dụng một ListView.Thêm chế độ xem vào LinearLayout theo lập trình
Tôi đang thêm nhận xét bằng vòng lặp và chương trình đi qua toàn bộ vòng lặp (được kiểm tra qua LogCat), nhưng chỉ thêm Chế độ xem (nhận xét) đầu tiên vào linearlayout.
Mã của tôi (trên thực tế tham số fillComments sẽ là một cái gì khác hơn là String []):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comment_layout);
String[] comments = {"kommentaar 1", "kommentaar 2", "kommentaar 3"};
mTitle = (TextView) findViewById(R.id.comments_title);
mTextArea = (EditText) findViewById(R.id.comment_editor);
mAddButton = (Button) findViewById(R.id.add_comment);
mCommentArea = (LinearLayout) findViewById(R.id.comments_area);
mTitle.setText(getIntent().getStringExtra("name"));
fillComments(comments);
}
private void fillComments(String[] comments) {
View comment;
TextView commentator;
TextView commentDate;
TextView commentText;
LayoutInflater inflater = getLayoutInflater();
for (String s : comments) {
Log.d("Comment adder", "Adding comment " + s);
comment = inflater.inflate(R.layout.comment_row_layout, null);
commentator = (TextView) comment.findViewById(R.id.commentator);
commentDate = (TextView) comment.findViewById(R.id.comment_date);
commentText = (TextView) comment.findViewById(R.id.comment_text);
commentator.setText("Test commentator");
commentDate.setText("12-12-2012");
commentText.setText(s);
mCommentArea.addView(comment);
}
}
Nó cũng sẽ xảy ra nếu 'R.id.comments_area' có hướng dọc + chiều rộng fill_parent? Và nhật ký ("Adder comment") có hiển thị nhiều lần không? – louiscoquio
bạn có thể vui lòng chỉ cho chúng tôi bố cục: comment_row_layout.xml .. Tôi có thể đoán bạn có định hướng ngang ... –