我编写了显示帖子和评论的AndroidApp 像任何社交群组一样对用户!我有帖子和列表 每个postItem我有评论列表但我不能 设置评论列表的大小!
我尝试: Set Height of ListView at run time in android &安培;&安培; Set ListView item height 但没有工作!
postList 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);
}
}
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;
}
然后我添加到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();
}
}
但不行!并且评论列表填写所有父母!并且无法查看其他帖子!
然后我尝试将评论列表更改为
View rowView = inflater.inflate(R.layout.comment,parent,false);
但只能查看一条评论!!!!!!! 请帮帮我!!!!!!!!!!!!!!!!!!
提前致谢。