0
我想插入一些LinearLayouts,但它不能像它應該那樣工作。它只插入一個,但它應該插入更多。用不同的值插入佈局
LinearLayout commentsContainer = (LinearLayout) findViewById(R.id.view_comment_container);
commentsContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
commentsContainer.setOrientation(LinearLayout.HORIZONTAL);
for (int i = 0; i < postView.commentLenght(); i++) {
Log.e("LENGTH", postView.commentLenght()+"x"+i);
LinearLayout commentContainer = new LinearLayout(PostViewActivity.this);
commentContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
LinearLayout userContainer = new LinearLayout(PostViewActivity.this);
userContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
userContainer.setOrientation(LinearLayout.VERTICAL);
commentContainer.setOrientation(LinearLayout.HORIZONTAL);
commentContainer.setPadding(25,0,0,0);
ImageView commentImage = new ImageView(PostViewActivity.this);
commentImage.setLayoutParams(new LinearLayout.LayoutParams((int) ((float) width/6), (int) ((float) width/6)));
commentImage.setImageBitmap(postView.getComment(i).getImage());
TextView commentText = new TextView(PostViewActivity.this);
commentText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
commentText.setText(postView.getComment(i).getText());
TextView displayUserText = new TextView(PostViewActivity.this);
displayUserText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
displayUserText.setText(postView.getComment(i).getDisplayName());
Log.d("TEXT", postView.getComment(i).getText());
Log.e("TEXT", displayUserText.getText()+"");
displayUserText.setTag(postView.getComment(i).getUsername());
displayUserText.setTextSize(12);
displayUserText.setTextColor(getResources().getColor(R.color.colorAccent));
userContainer.addView(commentImage);
userContainer.addView(displayUserText);
commentContainer.addView(userContainer);
commentContainer.addView(commentText);
commentsContainer.addView(commentContainer);
}
另一個奇怪的事情是:第一個Log.d總是正確的,但第二個總是相同的。什麼是錯誤?
謝謝!是的,這真的很好:-) – user6586661