如何在可单击的列表项中使用布局inflater和addview

时间:2014-12-03 01:28:56

标签: android json listview

我有一个JSON数组,如下所示。我需要使用这个数组填充listview,但我在JSON中有另一个数组(用于注释),我希望用它来使用addview()填充列表项中的linearlayout。如何设计我的列表适配器,我也需要这些注释也可以点击。

[
{
    "name": "Hopewell Mutanda",
    "answer": "This is my answer",
    "votes": 10,
    "date": 20-06-2014,
    "comments": [
                 {
                    "comment": "This is a great answer",
                    "name": "Gloria Nyakudya",
                    "date": 21-10-2014,
                    "vote": 20,
                 },
                 {
                    "comment": "This is the second great answer",
                    "name": "Pelagia Chirenga",
                    "date": 21-10-2014,
                    "vote": 10,
                 },
                 {
                    "comment": "This is the third great answer",
                    "name": "Pelagia Chirenga",
                    "date": 21-10-2014,
                    "vote": 0,
                 },
                ]
},
 {
    "name": "Tinashe Makaza",
    "answer": "This is the second  answer",
    "votes": 10,
    "date": 20-06-2014,
    "comments": [
                 {
                    "comment": "This is a great answer",
                    "name": "Gloria Nyakudya",
                    "date": 21-10-2014,
                    "vote": 20,
                 },
                 {
                    "comment": "This is the second great answer",
                    "name": "Pelagia Chirenga",
                    "date": 21-10-2014,
                    "vote": 10,
                 },
                 {
                    "comment": "This is the third great answer",
                    "name": "Pelagia Chirenga",
                    "date": 21-10-2014,
                    "vote": 0,
                 },
                ]
},

]

这是我希望实现的形象的链接。此布局中的每个值都是硬编码的

http://encodable.com/uploaddemo/files/Screenshot_2014-12-02-23-55-33.png

1 个答案:

答案 0 :(得分:1)

你应该看看ExpandableListView。这是默认的两级ListView。在我看来,这完全符合您的需求。