Good day. There is

LinearLayout entryPageCommentsList 

which I add comments from the page using the method

 private void addComment(final Map<String, Object> currentComment, int hashMapIndex) { View tmpView = getLayoutInflater().inflate(R.layout.entrypage_comment, null, false); ImageView entryCommentUSER_AVATAR = (ImageView) tmpView.findViewById(R.id.entryCommentUSER_AVATAR); TextView entryCommentUSER_NAME = (TextView) tmpView.findViewById(R.id.entryCommentUSER_NAME); TextView entryCommentDATE = (TextView) tmpView.findViewById(R.id.entryCommentDATE); TextView entryCommentRatingValue = (TextView) tmpView.findViewById(R.id.entryCommentRatingValue); TextView entryCommentMESSAGE = (TextView) tmpView.findViewById(R.id.entryCommentMESSAGE); imageLoader.displayImage(currentComment.get("USER_AVATAR").toString(), entryCommentUSER_AVATAR, displayImageOptions); entryCommentUSER_NAME.setText(currentComment.get("USER_NAME").toString()); entryCommentDATE.setText(timeAgo.getTimeAgo(currentComment.get("DATE").toString())); entryCommentRatingValue.setText(currentComment.get("COMMENT_RATING").toString()); entryCommentMESSAGE.setText(currentComment.get("MESSAGE").toString()); entryPageCommentsList.addView(tmpView); } 

Also available

 ArrayList<Map<String, Object>> commentsData 

To store HashMaps, which go to the addComment method. Sometimes you have to update the contents of commentsData, for example, when the comment rating changes. Then I use this code

 entryPageCommentsList.removeAllViews(); for(int i = 0; i < commentsData.size(); i++) addComment(commentsData.get(i), i); 

The oddity has gone since the moment you have to add a new HashMap to commentsData:

 public void updateComments() { if(commentsData.size() > 0) { commentsData.add(commentsData.get(commentsData.size() - 1)); for(int i = commentsData.size() - 1; i > 0; i--) commentsData.set(i, commentsData.get(i - 1)); } else { commentsData.add(new HashMap<String, Object>()); } commentsData.set(0, getNewCommentMap(response.get("HTML_CODE").toString())); entryPageCommentsList.removeAllViews(); for(int i = 0; i < commentsData.size(); i++) addComment(commentsData.get(i), i); } 

If at the very beginning the size of commentsData was greater than 0, then the addComment method works as it should, if there was no data initially in commentsData (commentsData is always initialized), then adding data in commentsData addComment stops working adequately, namely: new view's are not visible, although it shows in the logs that entryPageCommentsList.getChildCount () == 1 (i.e. essentially one child is added to the entryPageCommentsList, but it is not visible on the screen of the smartphone). I tried in the updateComments method at the very end to use entryPageCommentsList.invalidate (); entryPageCommentsList.requestLayout (); entryPageCommentsList.postInvalidate (); but none of the above helps. What could be the problem?

  • 2
    What is this bike? why not use a listview? - Roman Zakharov
  • Perhaps you have a "wrap_content" in the TextView in width and height, and when you add empty values ​​to them, their width with height becomes zero. - YurySPb
  • @Barmaley, we are not looking for easy ways =) remembered contact - Gorets
  • 2
    @ PhoEn-X in the ListView, you can add anything, the main thing to understand this. I advise you to go in the direction of ListView. What you choose is not correct. If there are more than 100 items on the list, you will start to lag terribly, I assure you. - andreich
  • one
    @ PhoEn-X, strange you say something. That is, downloading images for all elements does not immediately lag, and for 4-6 elements ListView - lags. Obviously, you are doing something wrong. Maybe all the same documentation yes samples read, no? - falstaf

1 answer 1

try the place Wrap_content fill_parent;