列表视图行中的更多复选框

时间:2017-02-04 03:54:19

标签: android json listview checkbox

我想知道是否可以在listView的单行中显示更多复选框 enter image description here

我已经显示了问题,但我不知道如何放置复选框。

我正在考虑使用自定义视图,但问题是复选框的数量是由jsonObject中的数组定义的,而且我不知道该怎么做

{
    "error": false,
    "question": {
        "idQuestion": "11435",
        "type": "MC",
        "extra": "",
        "fkLanguage": "1",
        "translation": "Electromagnetic radiation (light) holds energy. Which one of the following statements is correct?<\/P>",
        "answer": "",
        "0": [{
            "idAnswer": "49220",
            "score": "0",
            "fkQuestion": "11435",
            "fksub": null,
            "fkAnswer": "49220",
            "fkLanguage": "1",
            "translation": "Infrared radiation is richer in energy than visible radiation."
        }, {
            "idAnswer": "49221",
            "score": "0",
            "fkQuestion": "11435",
            "fksub": null,
            "fkAnswer": "49221",
            "fkLanguage": "1",
            "translation": "Infrared radiation is richer in energy than ultraviolet radiation."
        }, {
            "idAnswer": "49222",
            "score": "0",
            "fkQuestion": "11435",
            "fksub": null,
            "fkAnswer": "49222",
            "fkLanguage": "1",
            "translation": "Visible radiation is richer in energy than ultraviolet radiation."
        }, {
            "idAnswer": "49223",
            "score": "1",
            "fkQuestion": "11435",
            "fksub": null,
            "fkAnswer": "49223",
            "fkLanguage": "1",
            "translation": "Ultraviolet radiation is richer in energy than visible radiation."
        }]
    }
}

复选框必须显示答案,但是当我控制选中复选框时,我必须使用数组中提供的'idAnswer'

2 个答案:

答案 0 :(得分:0)

是的,您当然可以使用CustomListviews。 自定义列表视图可以自定义列表的行。

  1. 您需要定义包含所需数量的子布局 元素(这种情况下的复选框和文本视图)。

  2. 您需要一个模型类。

  3. 扩展基本适配器或的适配器类     arrayadapter
  4. 您可以参考此链接

    AndroidHive

    Vogella

    simplifiedCoding

答案 1 :(得分:0)

您需要使用两种类型{问题和答案}制作RecyclerView适配器。因此,您向适配器注入通用对象的arraylist。如果当前对象是问题,则必须使问题布局膨胀,如果对象是答案,则会使答案布局膨胀。查看使用getViewByType的任何示例。你的arraylist可能是[问题,答案,答案,问题,答案,答案,答案......]