jeudi 30 juin 2016

checkbox select all delete issue

i have checkboxes in custom list view and i have two seperate buttons one to select all and another to delete but i have big issue in it if i select one checkbox and select delete it works.but if i select all and delete it delete few of the data in lists ,for example i have 50 sms in list view once i select all and delete it delete few sms and again i press delete it delete another few like this..suggest some solutions

     sel.setOnClickListener(new View.OnClickListener() {
        @Override

     public void onClick(View v) {

     for (int i = 0; i <sms.size() ; i++) {

       if(sms.get(i).getChecked() == false ) {
                    sms.get(i).setChecked(true);
                }else if(sms.get(i).getChecked()==true) {
                    sms.get(i).setChecked(false);
                }


            }
            ((datalist)mlistView.getAdapter()).notifyDataSetChanged();
        }
    });
             del.setOnClickListener(new View.OnClickListener() {
        @Override

      public void onClick(View v) {


            for(int i=0; i<sms.size(); i++){
                if(sms.get(i).getChecked() == true){
                    sms.remove(i);
                }
            }


            ((datalist)mlistView.getAdapter()).notifyDataSetChanged();

        }




Aucun commentaire:

Enregistrer un commentaire