public void AddReview(Review review) {
final View v = LayoutInflater.from(context).inflate(R.layout.review_item, null, false);
final LinearLayout reviewList = (LinearLayout)findViewById(R.id.ReviewContainer);
final LinearLayout reviewExpander = (LinearLayout)findViewById(R.id.ReviewExpander);
TextView comment = (TextView)v.findViewById(R.id.Comment);
TextView author = (TextView)v.findViewById(R.id.Author);
comment.setText(review.Comment);
author.setText(review.User);
reviewList.addView(v);
v.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
if(addedReviews < minReviewsShowing) {
initReviewListHeight += v.getHeight();
initReviewListHeight = Math.min(initReviewListHeight, maximumInitHeight);
}
expandedreviewListHeight += v.getHeight();
addedReviews++;
if(addedReviews == reviewCount) {
reviewList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, initReviewListHeight));
if(expandedreviewListHeight <= initReviewListHeight) {
reviewExpander.setVisibility(View.GONE);
}
}
}
});
}