【问题标题】:More checkbox in a row of a listViewlistView 行中的更多复选框
【发布时间】:2017-02-04 03:54:18
【问题描述】:

我想知道是否可以像这样在 listView 的单行中显示更多复选框

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

我正在考虑使用自定义视图,但问题是复选框的数量是由 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”

【问题讨论】:

  • int numQuestions = jsonObject.getJSONArray("0").getLength()

标签: android json listview checkbox


【解决方案1】:

是的,您当然可以使用 CustomListviews。 custom listview可以自定义列表的行数。

  1. 您需要定义一个包含所需数量的子布局 元素(本例中的复选框和文本视图)。

  2. 你需要一个模型类。

  3. 扩展基本适配器的适配器类或 阵列适配器。

你可以参考这个链接

AndroidHive

Vogella

simplifiedCoding

【讨论】:

    【解决方案2】:

    您需要制作具有两种类型{问题和答案}的 RecyclerView 适配器。因此,您向适配器注入通用对象的数组列表。如果当前对象是问题,则必须扩展问题布局,如果对象是答案,则扩展答案布局。查看任何使用 getViewByType 的示例。您的数组列表可能类似于 [question, answer, answer, question, answer, answer, answer...]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 2016-04-01
      相关资源
      最近更新 更多