Программно добавлять представления в LinearLayout

У меня есть Activity, который отображает комментарии. У самих комментариев есть макет, поэтому я не могу просто использовать ListView.

Я добавляю комментарии с помощью цикла, и программа проходит весь цикл (проверяется с помощью LogCat), но добавляет только первое представление (комментарий) в linearlayout.

Мой код (на самом деле fillComments параметр будет чем-то другим, кроме 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);
    }
}
5
задан j0ntech 26 January 2012 в 10:40
поделиться