【问题标题】:change color on unchecked item to multiple_choice listview将未选中项目的颜色更改为 multiple_choice listview
【发布时间】:2015-06-16 21:03:00
【问题描述】:

我有一个listviewsimple_list_item_multiple_choice adapter,当我检查checkbox 项目之一时,这会取消选中其他checkboxes,直到这里很好,但我想更改其他backgroundcolor checkboxes 也是。

这是我的setadapter:

final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, values);
        listView.setAdapter(adapter);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

【问题讨论】:

    标签: android listview background-color multichoiceitems


    【解决方案1】:

    好的,我找到了解决方案,这里是同样的问题

    SparseBooleanArray checked = listView.getCheckedItemPositions();
                    int size = checked.size(); // number of name-value pairs in the array
                    for (int i = 0; i < size; i++) {
                        int key = checked.keyAt(i);
                        boolean value = checked.get(key);
                        if (value) {
                            row = listView.getChildAt(i);
                            row.setBackgroundColor(Color.parseColor("#33B5E5"));
                        }else{
                            row = listView.getChildAt(i);
                            row.setBackgroundColor(Color.parseColor("#F0F0F0"));
                        }
                    }
    

    row 是 View 全局变量,谢谢!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 1970-01-01
      • 2012-07-01
      • 2013-06-03
      相关资源
      最近更新 更多