I write the AndroidApp that show posts and comments to the user like any social group!I have list of post and in each postItem I have list of comment but I can't set size of commentlist !
I try: Set Height of ListView at run time in android && Set ListView item height but not work!
the customList for post:
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.post,null,true);
...
//view commentslist
if (cp.size() > 0) {
if (cp.get(String.valueOf(position)) != null) {
commentList adapter = new commentList(context, cp.get(String
.valueOf(position)));
ListView list = (ListView) rowView
.findViewById(R.id.listviewComment);
list.setAdapter(adapter);
}
}
the customlist for commentList:
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.comment,null, true);
TextView txt = (TextView) rowView.findViewById(R.id.TextComment);
txt.setText(web.get(position), BufferType.SPANNABLE);
return rowView;
}
then I add to customList:
for (int i = 0; i < adapter.getCount(); i++) {
View listItem = adapter.getView(i,null,list);
listItem.measure(0,0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = list.getLayoutParams();
params.height = totalHeight;
list.setLayoutParams(params);
list.requestLayout();
}
}
but not work! and the commentlist fill all parent!and can't view other posts!
then I try to change commentlist inflate to
View rowView = inflater.inflate(R.layout.comment,parent,false);
but only view one comment!!!!!!! please help me!!!!!!!!!!!!!!!!!!
Thanks in advance.