samedi 3 octobre 2020

get items that check on checkbox android

I want to get the items to be checked with the checkbox. This is the adapter code:

 holder.checkb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    projectEntityList.get(position).setSelected(holder.checkb.isChecked());

                }
            }
        });

Then here I want to use the items that have been checked. When I query for list of projects, the selected items are saved, but when it enters the for, all the items that were checked become unChecked.

 private void addProject() {
        try {
            projectEntityList = DatabaseManager.getDatabaseHelper(this).getProjectDao().queryForAll();
            for (int i = 0; i < projectEntityList.size(); i++) {
                if (projectEntityList.get(i).isSelected()) {
                    helper.getProjectDao().createOrUpdate(projectEntityList.get(i));
                }

            }
            Log.i("TESTTEST",   "projectEntity" + projectEntity);
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }

look at the debugs photo:

debug before for

debug after for




Aucun commentaire:

Enregistrer un commentaire