Problems with checkbox in an android view Adapter

Asked

Viewed 29 times

0

inserir a descrição da imagem aqui

In the example image it shows three checkboxes in a line of a listview. But I have to make a way in which, by checking 1 checkbox, uncheck others on the same line that are marked. You have how to do this?

public View getView(int position, View convertView, ViewGroup parent) {
        PedidoItem item = itens.get(position);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.item_separacao, null);

        TextView referencia = view.findViewById(R.id.txt_ref_sep);
        referencia.setText(item.getProduto());

        TextView tamanho = view.findViewById(R.id.txt_tam_sep);
        tamanho.setText(String.valueOf(item.getTamanho()));

        CheckBox separado = view.findViewById(R.id.ch_sep);
        CheckBox corrigir = view.findViewById(R.id.ch_corrigir);
        CheckBox manual = view.findViewById(R.id.ch_manual);

        return view;
    }

I tried doing that:

if(corrigir.isChecked()){
    separado.setChecked(false);
    manual.setChecked(false);
}

if(manual.isChecked()){
    separado.setChecked(false);
    corrigir.setChecked(false);
}

still does not clear

1 answer

0


Try something like this

seuCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                    if(corrigir.isChecked()){
                        separado.setChecked(false);
                        manual.setChecked(false);
                    }

                    if(manual.isChecked()){
                        separado.setChecked(false);
                        corrigir.setChecked(false);
                    }
        }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.