Ajout de Vues à LinearLayout par programmation
J'ai une Activité qui affiche les commentaires. Les commentaires eux-mêmes ont une mise en page, donc je ne peux pas simplement utiliser un ListView.
Je suis en ajoutant les commentaires avec une boucle, et le programme passe à travers la totalité de la boucle (vérifiée par LogCat), mais ajoute seulement le premier point de Vue (commentaire) pour le linearlayout.
Mon code (en réalité le fillComments paramètre sera quelque chose d'autre que 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);
}
}
C'est également le cas si
pouvez vous s'il vous plaît nous montrer la mise en page: comment_row_layout.xml.. je peux deviner que vous avez orientation horizontale...
R.id.comments_area
a l'orientation verticale + largeur fill_parent ? Et c'est le journal ("Commentaire adder") affichés plusieurs fois ?pouvez vous s'il vous plaît nous montrer la mise en page: comment_row_layout.xml.. je peux deviner que vous avez orientation horizontale...
OriginalL'auteur j0ntech | 2012-01-26
Vous devez vous connecter pour publier un commentaire.
je pense
mCommentArea = (LinearLayout) findViewById(R.id.comments_area);
cette disposition de l'orientation est Horizontale donc ce problèmes se produit. s'il vous plaît si les orientations horizontales puis changez-le à la verticale et profiter de
OriginalL'auteur Ramesh Solanki
Comment avez-vous défini le LinearLayout? Il pourrait être juste un problème d'affichage.
De vérifier la taille et l'orientation de LinearLayout.
android:orientation="vertical"
ligne à mon LinearLayout.OriginalL'auteur user1169390