我已经创建了xml-layout文件,其中包含View类评论框。我希望在getView()方法中多次创建动态布局(注释框)。如何在getView()方法中动态创建它?
在这里,在getview()方法中,我多次使用代码动态生成特定的View,但是它不起作用。请给我建议。
我的适配器代码链接如下:
http://pastebin.com/aAYdPbn9
发布于 2014-12-02 12:43:48
我给你看了三条路。正如评论中所讨论的,您问题的标题具有误导性,因此我认为:
因此,根本的问题是,您有一个二维数据结构,您希望使用一维UI组件(在您的例子中是ListView )来显示它。
你可以通过以下方式解决你的问题:
getView()方法中,您需要执行如下操作:
if(list.get(position) instanceOf Card) return getCardView(...); else if(list.get(position) instanceOf Comment) return getCommentView(...);View commentConvertView = inflater.inflate(R.layout.list_item_comment, ...); ViewGroup comments = (ViewGroup) convertView.findViewById(R.id.llComments); comments.removeAllView; for(list.get(position).getComments()){ //bind the data to commentConvertView comments.add(commentConvertView); }1 2
https://stackoverflow.com/questions/27249397
复制相似问题