Get Selected Item Using Checkbox in Listview

前端 未结 9 693
醉酒成梦
醉酒成梦 2020-11-22 09:36

I am creating an Android application where I have a ListView that displays all of the applications that were installed in my mobile phone.

My ListView is customized,

9条回答
  •  伪装坚强ぢ
    2020-11-22 09:51

    make the checkbox non-focusable, and on list-item click do this, here codevalue is the position.

        Arraylist selectedschools=new Arraylist();
    
        lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() 
      {
    
       @Override
            public void onItemClick(AdapterView parent, View view, int codevalue, long id)
       {
                          CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus);
    
                cb.setChecked(!cb.isChecked());
                if(cb.isChecked())
                {
    
                    if(!selectedschool.contains(codevaule))
                    {
                        selectedschool.add(codevaule);
                    }
                }
                else
                {
                    if(selectedschool.contains(codevaule))
                    {
                        selectedschool.remove(codevaule);
                    }
                }
            }
        });
    

提交回复
热议问题