Know which checkboxes are selected in the adapter and perform operations on the activity based on the selected checks

0

Hello,Ihavealist(ListView)andwhenIselectoption1inmyspinnerit'svisibleinframelayouttoshowonthescreenacheckboxforcadadlistitemwith0pstatus,IwaswonderingwhichchecksboxsareselectedintheadapterforthatinactivityIcanincludeinalistandchangestatus.Thisismyactivity:

spinnerSync.setOnItemSelectedListener(newAdapterView.OnItemSelectedListener(){@OverridepublicvoidonItemSelected(finalAdapterView<?>parent,finalViewview,finalintposition,longid){//GuardonavariavelestaticaparanoadapterfazeraverificaçãosemostraounãoacheckPOSITION=position;//Criaalistanaactivityadapter2=newSyncAdapter2(listaForm,getApplicationContext());listView.setAdapter(adapter2);buttonSync.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){//VerificarquaisitensdalistViewestãocheckados(checkbox)//Pegaraposiçãodositenscheckado//incluiformnoSQLiteeconsequentementenalistaagendaif(listaForm.get(position).getStatus()==0){dao.incluir(listaForm);}Handlerhandler=newHandler();handler.postDelayed(newRunnable(){publicvoidrun(){load.setVisibility(View.GONE);}},3000L);load.setVisibility(View.VISIBLE);}});}@OverridepublicvoidonNothingSelected(AdapterView<?>parent){}});

Andthisismyadapter:

@OverridepublicViewgetView(finalintposition,finalViewconvertView,ViewGroupparent){Viewv=View.inflate(context,R.layout.sinc_item_listview2,null);checkBox=(CheckBox)v.findViewById(R.id.checkbox);checkBox.setVisibility(View.GONE);if(SincActivity.POSITION==1){if(listForm.get(position).getStatus()!=1)checkBox.setVisibility(View.VISIBLE);TextViewtvDayNumber=(TextView)v.findViewById(R.id.tvDayNumber);tvDayNumber.setText(listForm.get(position).getDataForm());tvDayNumber.setTypeface(tf);TextViewtvDayWeek=(TextView)v.findViewById(R.id.tvDayWeek);tvDayWeek.setText(listForm.get(position).getDataForm());tvDayWeek.setTypeface(tf);TextViewtvLocation=(TextView)v.findViewById(R.id.tvLocation);tvLocation.setText("#" + listForm.get(position).getNomeLoja());
            tvLocation.setTypeface(tf);
            TextView tvHour = (TextView) v.findViewById(R.id.tvHour);
            tvHour.setText(listForm.get(position).getHora() + " | ");
            tvHour.setTypeface(tf);
            TextView tvForms = (TextView) v.findViewById(R.id.tvForm);
            tvForms.setText(listForm.get(position).getNomeFom());
            tvForms.setTypeface(tf);

            ImageView imageInfo = (ImageView) v.findViewById(R.id.imageInfo);
            if (listForm.get(position).getStatus() == 1) {
                imageInfo.setImageResource(R.drawable.checked);
            } else {
                imageInfo.setImageResource(R.drawable.exclamation);
            }
    } else {
        TextView tvDayNumber = (TextView) v.findViewById(R.id.tvDayNumber);
        tvDayNumber.setText(listForm.get(position).getDataForm());
        tvDayNumber.setTypeface(tf);
        TextView tvDayWeek = (TextView) v.findViewById(R.id.tvDayWeek);
        tvDayWeek.setText(listForm.get(position).getDataForm());
        tvDayWeek.setTypeface(tf);
        TextView tvLocation = (TextView) v.findViewById(R.id.tvLocation);
        tvLocation.setText("#" + listForm.get(position).getNomeLoja());
        tvLocation.setTypeface(tf);
        TextView tvHour = (TextView) v.findViewById(R.id.tvHour);
        tvHour.setText(listForm.get(position).getHora() + " | ");
        tvHour.setTypeface(tf);
        TextView tvForms = (TextView) v.findViewById(R.id.tvForm);
        tvForms.setText(listForm.get(position).getNomeFom());
        tvForms.setTypeface(tf);

        ImageView imageInfo = (ImageView) v.findViewById(R.id.imageInfo);
        if (listForm.get(position).getStatus() == 1) {
            imageInfo.setImageResource(R.drawable.checked);
        } else {
            imageInfo.setImageResource(R.drawable.exclamation);
        }
    }



    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked){
                Toast.makeText(context,"Checkado",Toast.LENGTH_SHORT).show();
                Log.w("id",position+"");
                listaInteger.add(listForm.get(position).getIdForm());

            }else{
                Toast.makeText(context,"uncheck",Toast.LENGTH_SHORT).show();
                Log.w("id",position+"");
                listaInteger.remove(listForm.get(listForm.get(position).getIdForm()).getIdForm());
            }
        }
    });


    v.setTag(listForm.get(position).getIdForm());

    return v;
}
    
asked by anonymous 09.12.2016 / 18:10

0 answers