我有一个自定义列表视图,用帖子填充我的屏幕。一些帖子有评论,这就是为什么我需要其他列表视图,以便评论可以与帖子一起显示。我正在使用排球,并制作了一个post类,它具有不同属性的getter和setter方法。我正在使用自定义列表View适配器来显示帖子详细信息,但我也不明白如何显示评论。有人可以通过解释实现这一目标的最佳方法来帮助我吗?
这是将使用的JSON示例:
{
id: "10",
author_id: "1",
name: "John",
picture: "uploads/image.jpg",
text: "hello this is my first post:)"
comments: [
{
comment: "Hello",
comment_id: "1",
comment_author_id: "2",
post_id: "10"
},
{
comment: "Hi",
comment_id: "2",
comment_author_id: "1",
post_id: "10"
},
]
},
{
id: "11",
author_id: "3",
name: "Jane",
picture: "uploads/image_2.jpg",
text: "hello World ! "
comments: []
},
我希望它看起来像下面的图片,所以评论与帖子一起显示: http://i.stack.imgur.com/RfzNw.jpg
任何帮助都会很棒:)
答案 0 :(得分:0)
您无法将listview放在listview中。您应该添加布局等注释。
LinearLayout commentsLayout = (LinearLayout)findViewById(R.id.commentsLayout);
View comment = getLayoutInflater().inflate(R.layout.comment);
commentsLayout.addView(comment);
答案 1 :(得分:0)
你应该为列表视图制作一个自定义适配器,这意味着你为每一行设置一个布局,然后解析json ..我认为这个链接可以帮助你:https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView