简体   繁体   中英

ListView inside another ListView

i have a custom list View that populates my screen with posts. some of the posts have comments which is why I need the other list View so that the comments can be displayed with the post. I'm using volley and have made a post class which has getter and setter methods for the different attributes. I'm using a custom list View adapter to display the post details but I don't understand how to display the comments as well. Could someone please help me by explaining the best way to achieve this?

this is an example of the JSON that will be used:

{ 
  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: []
},

I would like it to look like the image below, so comments are displayed with the post: http://i.stack.imgur.com/RfzNw.jpg

Any help would be great :)

You can't put listview in listview. You should add comments like layouts.

LinearLayout commentsLayout = (LinearLayout)findViewById(R.id.commentsLayout);
View comment = getLayoutInflater().inflate(R.layout.comment);
commentsLayout.addView(comment);

您应该为列表视图创建一个自定义适配器,这意味着您为每行设置一个布局,然后解析json ..我认为此链接将为您提供帮助: https : //github.com/codepath/android_guides/wiki/使用带有ListView的ArrayAdapter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM