Scrolling through listview scroll delete edittext data

3

Good morning afternoons I have a listview that I fill with a custom adapter in which I have an edittext so that the user can put a quantity, the problem is when I have more than 5 rows in my listview and enter in the first one, and I scroll down and then back up, the information is lost what was in that edittext

I leave my code

public MyArrayAdapter(Context context, ArrayList<DetalleCxP> ArrayClientes) {
            super(context, 0, ArrayClientes);
        }

        public View getView(int position, View convertView, ViewGroup parent) {

            DetalleCxP O_DetalleCxP = getItem(position);
            if (convertView == null)
            {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_detalle, parent, false);
                ((EditText) convertView.findViewById(R.id.edt_abono)).addTextChangedListener(new TB_Abono_Watcher(convertView));
            }

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

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

            ((TextView)convertView.findViewById(R.id.txtFecha)).setText(dateFormat.format(O_DetalleCxP.getFecha()));

            //O_DetalleCxP.setViewChanged(true);
            ((EditText) convertView.findViewById(R.id.edt_abono)).setTag(O_DetalleCxP);
            ((TextView)convertView.findViewById(R.id.txtFolio)).setText(O_DetalleCxP.getFolio());


            if (O_DetalleCxP.TotalAplicado>0)
            {

            }
            else
            {
                ((EditText)convertView.findViewById(R.id.edt_abono)).setText("");
            }
           // ((EditText) convertView.findViewById(R.id.edt_abono)).setText(numberFormat.format(O_DetalleCxP.TotalAplicado));

            ((TextView)convertView.findViewById(R.id.total)).setText(numberFormat.format(O_DetalleCxP.getTotal()));
            ((TextView)convertView.findViewById(R.id.txttotal)).setText(numberFormat.format(O_DetalleCxP.getSaldo()));
            ((TextView)convertView.findViewById(R.id.txtvencido)).setText(numberFormat.format(O_DetalleCxP.getSaldoVencido()));
            //((TextView)convertView.findViewById(R.id.parcialidad)).setText((numberFormat.format(O_DetalleCxP.getParcialidadTotal()) +" - "+ O_DetalleCxP.getParcialidad()));
            ((TextView)convertView.findViewById(R.id.pagoforma)).setText(O_DetalleCxP.getPagoCondicionDescripcion());
            ((TextView)convertView.findViewById(R.id.UltimoCobroObservacion)).setText(O_DetalleCxP.getUltimoCobroObservacion());


            //Devolver al ListView la fila creada
            return convertView;
        }
    }

and in this code I make a sum of the amounts entered in the edittext

 public void afterTextChanged(Editable s)
        {

            //Abono = (EditText)view.findViewById(R.id.edt_abono);
            DetalleCxP O_DetalleCxP = (DetalleCxP)((EditText)view.findViewById(R.id.edt_abono)).getTag();


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

                Double Total=0.0;
                for(int i=0;i<DetalleArrayList.size();i++)
                {
                    if (((DetalleCxP)DetalleArrayList.get(i)).TotalAplicado>0)
                    {
                        Total += ((DetalleCxP)DetalleArrayList.get(i)).TotalAplicado;
                    }
                }
                DecimalFormat numberFormat  = new DecimalFormat("###,##0.00");
                ((TextView)findViewById(R.id.Total)).setText(numberFormat.format(Total));

                if (Total==0)
                {
                    ((Button)findViewById(R.id.pagoceros)).setEnabled(true);
                    ((Button)findViewById(R.id.pago)).setEnabled(false);
                }
                else
                {
                    ((Button)findViewById(R.id.pagoceros)).setEnabled(false);
                    ((Button)findViewById(R.id.pago)).setEnabled(true);
                }

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

                }
    
asked by Hugo Rodriguez 16.06.2016 в 21:39
source

2 answers

1

You have that add the empty text when you create the view, when the convertView is Null:

 if (convertView == null)
        {
            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_DetalleCxP);
             ((EditText)convertView.findViewById(R.id.edt_abono)).setText("");
        }
    
answered by 16.06.2016 в 22:38
1

The problem is that you do not notify the changes that you insert, and when you scroll, it is downloaded from the memory and when you return to the same position, it shows you the value that you have initially.

To fix it, you must specify the changes when you enter the data

tuadaptador.notifyDataSetChanged()
    
answered by 17.06.2016 в 11:47