在复选框选择上选择列表视图中的所有项目 [英] Selecting All Items in a Listview on checkbox select

查看:16
本文介绍了在复选框选择上选择列表视图中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 simple_list_item_multiple_choice 的简单 listView我添加了一个复选框,并在其选中的事件上希望所有列表项都被选中,而在未选中的所有项目上都被取消选中..这是代码..

I am using simple listView with simple_list_item_multiple_choice I have added a checkbox and on its checked event want all list items to get selected and on unchecked all items to get unselected.. Here is the code..

CheckBox select_all = (CheckBox) dialog.findViewById(R.id.chk_all);
        arrayAdapter = new ArrayAdapter<String>
        (ctx,android.R.layout.simple_list_item_multiple_choice,readyToDownload );
        lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        lv.setAdapter(arrayAdapter);

   select_all.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
            if(select_all.isChecked())
            {
                // check all list items
            }
            if(!select_all.isChecked())
                {
                    //  unselect all list items
                }

            }
                }); 

推荐答案

for ( int i=0; i < listview.getChildCount(); i++) {
   listview.setItemChecked(i, true);
}

这篇关于在复选框选择上选择列表视图中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆