Problem with android custoadapter

0

I have a customadapter in which I charge customer details.

The detail that I have is that I have a edittex in each item that I show me information and a client may have 10 details or sales notes to apply a payment the detail is that when I walk my scrolll towards down the data entered in the top part I deleted them

            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_detalle, parent, false);
            ((EditText) convertView.findViewById(R.id.edt_abono)).addTextChangedListener(new TB_Abono_Watcher(convertView));


            ((EditText) convertView.findViewById(R.id.edt_abono)).setTag(O_CXCPDetalle);
            if (O_CXCPDetalle.TotalAplicado != 0) {
                ((EditText) convertView.findViewById(R.id.edt_abono)).setText(String.valueOf(O_CXCPDetalle.TotalAplicado));


            } else {
                ((EditText) convertView.findViewById(R.id.edt_abono)).setText("");
            }



            viewHolder.txfecha = (TextView) convertView.findViewById(R.id.txtFecha);
            viewHolder.txfolio = (TextView) convertView.findViewById(R.id.txtFolio);
            viewHolder.txtotal = (TextView) convertView.findViewById(R.id.total);
            viewHolder.txttotal = (TextView) convertView.findViewById(R.id.txttotal);
            viewHolder.vencido = (TextView) convertView.findViewById(R.id.txtvencido);
            viewHolder.parcialidad = (TextView) convertView.findViewById(R.id.parcialidad);
            viewHolder.pagoforma = (TextView) convertView.findViewById(R.id.pagoforma);
            viewHolder.ultimocobroob = (TextView) convertView.findViewById(R.id.UltimoCobroObservacion);
            viewHolder.checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);
            viewHolder.checkBox.setTag(new Integer(position));




            result = convertView;

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            result = convertView;
           // viewHolder.checkBox.setOnCheckedChangeListener(null);
        }


        DecimalFormat numberFormat = new DecimalFormat("###,##0.00");

        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

        viewHolder.checkBox.setFocusable(false);
        viewHolder.txfecha.setText(dateFormat.format(O_CXCPDetalle.getFecha()));
        viewHolder.txfolio.setText(O_CXCPDetalle.getFolio());
        viewHolder.txtotal.setText(numberFormat.format(O_CXCPDetalle.getTotal()));
        viewHolder.txttotal.setText(numberFormat.format(O_CXCPDetalle.getSaldo()));
        viewHolder.vencido.setText(numberFormat.format(O_CXCPDetalle.getSaldoVencido()));
        viewHolder.parcialidad.setText((numberFormat.format(O_CXCPDetalle.getParcialidadTotal()) + " - " + O_CXCPDetalle.getParcialidad()));
        viewHolder.pagoforma.setText(O_CXCPDetalle.getPagoCondicionDescripcion());
        viewHolder.ultimocobroob.setText(O_CXCPDetalle.getUltimoCobroObservacion());
        viewHolder.checkBox.setEnabled(true);


     /*   viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked ){
                    System.out.println(position+"--- :)");
                    O_CXCPDetalle.setstatuscheck(true);

                }else{
                    O_CXCPDetalle.setstatuscheck( false);
            }
            }
        });*/

  /*          viewHolder.checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (((CheckBox) v).isChecked()) {
                    O_CXCPDetalle.statuscheck = true;

                } else {
                   O_CXCPDetalle.statuscheck = false;
                }
            }
        });*/


        double Abono = 0.00;
        Abono = O_CXCPDetalle.getTotal() - O_CXCPDetalle.getSaldo();
        ((TextView) convertView.findViewById(R.id.pagado)).setText(numberFormat.format(Abono));

        // Return the completed view to render on screen
        return convertView;
    }
}

and I use the techwacher to do the addition operation

public void afterTextChanged(Editable s)
    {
        final CXCPDetalle o_CXCP_Detalle = (CXCPDetalle)((EditText)view.findViewById(R.id.edt_abono)).getTag();

        SharedPreferences settings = getSharedPreferences("ONC_Settings", 0);
        if (settings.getInt("ONControlConexion", 0) == 0) {
            if (o_CXCP_Detalle.getViewChanged()==false) {

                o_CXCP_Detalle.TotalAplicado = ONC_SYS.NullToZeroDouble(s.toString());

                Double Total = 0.00;
                for (int i = 0; i < O_Resultado.DetalleArray.size(); i++) {
                    if (((CXCPDetalle) O_Resultado.DetalleArray.get(i)).TotalAplicado > 0) {
                        Total += ((CXCPDetalle) O_Resultado.DetalleArray.get(i)).TotalAplicado;
                        ((CheckBox)view.findViewById(R.id.checkBox)).setChecked(true);

                    }
                }
                DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
                ((TextView) findViewById(R.id.Total)).setText(numberFormat.format(Total));


             ((CheckBox)view.findViewById(R.id.checkBox)).setEnabled(true);
               ((CheckBox)view.findViewById(R.id.checkBox)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                        SharedPreferences settings = getSharedPreferences("ONC_Settings", 0);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString("ONControlCheck", String.valueOf(isChecked));
                        editor.commit();

                        o_CXCP_Detalle.setStatusCheck(String.valueOf(isChecked));


                        if (o_CXCP_Detalle.getStatusCheck() == "true")
                        {

                            ((Button)findViewById(R.id.pago)).setEnabled(true);
                            ((EditText) view.findViewById(R.id.edt_abono)).setEnabled(true);


                        }else
                        {
                            DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
                            ((EditText) view.findViewById(R.id.edt_abono)).setText("");
                            ((EditText) view.findViewById(R.id.edt_abono)).setEnabled(false);
                            ((TextView) findViewById(R.id.Total)).setText(numberFormat.format(0.00));
                        }
                    }
                });




               if (o_CXCP_Detalle.getStatusCheck() == "true")
                {
                    ((Button)findViewById(R.id.pago)).setEnabled(true);
                    ((EditText) view.findViewById(R.id.edt_abono)).setEnabled(true);

                }else
                {
                    ((EditText) view.findViewById(R.id.edt_abono)).setEnabled(false);
                }

                //Validacion que no te deje hacer un abono Mayo al saldo vencido
                 if (o_CXCP_Detalle.getSaldo() < o_CXCP_Detalle.TotalAplicado) {
                    Toast.makeText(getApplicationContext(), "No puedes Aplicar un Abono Mayor al SaldoVencido", Toast.LENGTH_SHORT).show();
                    ((EditText) view.findViewById(R.id.edt_abono)).setText("");

                }
            }

public class CustomAdapter extends ArrayAdapter {

    private Detalle_Cliente dataSet;
    Context mContext;
    boolean[] checkBoxState;

    // View lookup cache
    public class ViewHolder {

        public TextView txfecha = null;
        public TextView txfolio = null;
        public TextView txtotal = null;
        public TextView txttotal = null;
        public TextView vencido = null;
        public TextView parcialidad = null;
        public TextView pagoforma = null;
        public TextView ultimocobroob = null;
        public CheckBox checkBox = null;
        public EditText cantidad;


    }

    public CustomAdapter(Detalle_Cliente data, ArrayList context) {
        super(data, R.layout.row_detalle, context);
        this.dataSet = data;

    }

    private int lastPosition = -1;



    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        final CXCPDetalle O_CXCPDetalle = getItem(position);
       // final ListViewItem item = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        final ViewHolder viewHolder; // view lookup cache stored in tag

        final View result;

        if (convertView == null) {

            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_detalle, parent, false);
            ((EditText) convertView.findViewById(R.id.edt_abono)).addTextChangedListener(new TB_Abono_Watcher(convertView));


            ((EditText) convertView.findViewById(R.id.edt_abono)).setTag(O_CXCPDetalle);
            if (O_CXCPDetalle.TotalAplicado != 0) {
                ((EditText) convertView.findViewById(R.id.edt_abono)).setText(String.valueOf(O_CXCPDetalle.TotalAplicado));


            } else {
                ((EditText) convertView.findViewById(R.id.edt_abono)).setText("");
            }



            viewHolder.txfecha = (TextView) convertView.findViewById(R.id.txtFecha);
            viewHolder.txfolio = (TextView) convertView.findViewById(R.id.txtFolio);
            viewHolder.txtotal = (TextView) convertView.findViewById(R.id.total);
            viewHolder.txttotal = (TextView) convertView.findViewById(R.id.txttotal);
            viewHolder.vencido = (TextView) convertView.findViewById(R.id.txtvencido);
            viewHolder.parcialidad = (TextView) convertView.findViewById(R.id.parcialidad);
            viewHolder.pagoforma = (TextView) convertView.findViewById(R.id.pagoforma);
            viewHolder.ultimocobroob = (TextView) convertView.findViewById(R.id.UltimoCobroObservacion);
            viewHolder.checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);
            viewHolder.checkBox.setTag(new Integer(position));




            result = convertView;

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            result = convertView;
           // viewHolder.checkBox.setOnCheckedChangeListener(null);
        }


        DecimalFormat numberFormat = new DecimalFormat("###,##0.00");

        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

        viewHolder.checkBox.setFocusable(false);
        viewHolder.txfecha.setText(dateFormat.format(O_CXCPDetalle.getFecha()));
        viewHolder.txfolio.setText(O_CXCPDetalle.getFolio());
        viewHolder.txtotal.setText(numberFormat.format(O_CXCPDetalle.getTotal()));
        viewHolder.txttotal.setText(numberFormat.format(O_CXCPDetalle.getSaldo()));
        viewHolder.vencido.setText(numberFormat.format(O_CXCPDetalle.getSaldoVencido()));
        viewHolder.parcialidad.setText((numberFormat.format(O_CXCPDetalle.getParcialidadTotal()) + " - " + O_CXCPDetalle.getParcialidad()));
        viewHolder.pagoforma.setText(O_CXCPDetalle.getPagoCondicionDescripcion());
        viewHolder.ultimocobroob.setText(O_CXCPDetalle.getUltimoCobroObservacion());
        viewHolder.checkBox.setEnabled(true);


     /*   viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked ){
                    System.out.println(position+"--- :)");
                    O_CXCPDetalle.setstatuscheck(true);

                }else{
                    O_CXCPDetalle.setstatuscheck( false);
            }
            }
        });*/

/ * viewHolder.checkBox.setOnClickListener (new View.OnClickListener () {                 @Override                 public void onClick (View v) {

                if (((CheckBox) v).isChecked()) {
                    O_CXCPDetalle.statuscheck = true;

                } else {
                   O_CXCPDetalle.statuscheck = false;
                }
            }
        });*/


        double Abono = 0.00;
        Abono = O_CXCPDetalle.getTotal() - O_CXCPDetalle.getSaldo();
        ((TextView) convertView.findViewById(R.id.pagado)).setText(numberFormat.format(Abono));

        // Return the completed view to render on screen
        return convertView;
    }
}
    
asked by Hugo Rodriguez 06.01.2017 в 00:00
source

1 answer

1

This is the result of the recycling that the ListView uses, this is used for better memory performance.

What you can do is in the textWatcher save the data that the user wrote in the edittext of the items in the list in the item O_CXCPDetalle

And in the getView of your adapter recover the data again, so when the listView reclicle the items when you recreate the item it will still have the same value as you are saving it.

In this question you can read more information about how ListView works: link

    
answered by 01.09.2018 в 16:08