【问题标题】:Verify if there are any selected items in a gridview验证网格视图中是否有任何选定的项目
【发布时间】:2017-06-03 15:02:13
【问题描述】:

我正在开发一个应用程序并实现一个引导,以要求用户选择将在网格视图中显示的某些选项。我希望用户使用在我的项目条目类中声明的简单的 toggleSelected(){selected=!selected} 来选择和取消选择这个 im 的项目。 如果gridview 中的所有项目都具有isSelected() = false,我在底部还有一个按钮将被禁用。检查这个的最好方法是什么? 感谢您的帮助

【问题讨论】:

    标签: android gridview


    【解决方案1】:

    In the model class which actually contains the data,the list which you provide to the adapter of the recyclerView , add a variable isSelected and set its default value to false, whenever a grid item gets selected, set it to true and when它被取消选中,将其设置为 false。通过这种方式,您可以遍历该列表,然后知道哪些被选中,哪些未被选中。

    【讨论】:

      【解决方案2】:

      一种方法是遍历所有元素并检查是否选择了任何元素。 但这会占用大量资源。

      我宁愿建议您保留所选元素的数量。 如果 count != 0,则启用您的按钮。

      【讨论】:

        猜你喜欢
        • 2015-09-09
        • 1970-01-01
        • 2010-11-07
        • 2023-03-26
        • 1970-01-01
        • 2014-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多