1

I know this question is asked many times before and followed them and I am up to the mark to a great extent with only one problem left.I was able to solve the duplicating issue by adding textwatcher and using hashmap to store value but problem that is left is that the value of original edit text is also gone when I scroll back to it. By this I mean that if I type something in say first EditText and then scroll down, that value doesn't get repeated anywhere but the value of EditText in which I typed is also gone. Here is my code.

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.list_planmanobra_row, parent, false);
            holder.periodo_zafra = (TextView) convertView.findViewById(R.id.periodo_zafra);
            holder.CODIGO_FINCA = (TextView) convertView.findViewById(R.id.CODIGO_FINCA);
            //holder.NOMBRE_FINCA = (TextView) convertView.findViewById(R.id.NOMBRE_FINCA);
            holder.MES = (TextView) convertView.findViewById(R.id.MES);
            holder.CLAVE = (TextView) convertView.findViewById(R.id.CLAVE);
            holder.NOMBRE_CLAVE = (TextView) convertView.findViewById(R.id.NOMBRE_CLAVE);
            holder.CODIGO_ESTANDAR = (TextView) convertView.findViewById(R.id.CODIGO_ESTANDAR);
            holder.NOMBRE_ESTANDAR_MO = (TextView) convertView.findViewById(R.id.NOMBRE_ESTANDAR_MO);
            holder.CANTIDAD_ESTANDAR = (TextView) convertView.findViewById(R.id.CANTIDAD_ESTANDAR);
            holder.VALOR_UNITARIO = (TextView) convertView.findViewById(R.id.VALOR_UNITARIO);
            holder.VALOR_TOTAL = (TextView) convertView.findViewById(R.id.VALOR_TOTAL);
            holder.EJECUTA = (TextView) convertView.findViewById(R.id.EJECUTA);
            holder.btn_submit= (Button) convertView.findViewById(R.id.btn_submit);
            holder.btn_submit.setText("Enviar");
            holder.Cantidad= (EditText) convertView.findViewById(R.id.et_cantidad);
            holder.Cantidad_empleados= (EditText) convertView.findViewById(R.id.Cantidad_empleados);
            holder.checkbox= (CheckBox) convertView.findViewById(R.id.checkbox);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.periodo_zafra.setText(planmanobraBeanArrayList.get(position).getPERIODO_ZAFRA());
        holder.CODIGO_FINCA.setText(planmanobraBeanArrayList.get(position).getCODIGO_FINCA());
       // holder.NOMBRE_FINCA.setText(planiBeanArrayList.get(position).getNOMBRE_FINCA());
        holder.MES.setText(planmanobraBeanArrayList.get(position).getMES());
        holder.CLAVE.setText(planmanobraBeanArrayList.get(position).getCLAVE());
        holder.NOMBRE_CLAVE.setText(planmanobraBeanArrayList.get(position).getNOMBRE_CLAVE());
        holder.CODIGO_ESTANDAR.setText(planmanobraBeanArrayList.get(position).getCODIGO_ESTANDAR());
        holder.NOMBRE_ESTANDAR_MO.setText(planmanobraBeanArrayList.get(position).getNOMBRE_ESTANDAR_MO());
        holder.CANTIDAD_ESTANDAR.setText(planmanobraBeanArrayList.get(position).getCANTIDAD_ESTANDAR());
        holder.VALOR_UNITARIO.setText(planmanobraBeanArrayList.get(position).getVALOR_UNITARIO());
        holder.VALOR_TOTAL.setText(planmanobraBeanArrayList.get(position).getVALOR_TOTAL());
        holder.EJECUTA.setText(planmanobraBeanArrayList.get(position).getEJECUTA());
        holder.Cantidad.setText(editTextList.get(position));
        holder.Cantidad.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                editTextList.put(position,charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        holder.btn_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


            }
        });
        return convertView;
    }

Cantidad is the edit text

salih kallai
  • 879
  • 2
  • 13
  • 34
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
  • Refer here this might give u some help http://coderzpassion.com/android-custom-listview-with-edittext/ – Jagjit Singh Mar 13 '16 at 08:22
  • what happens is, the model (data holder, in ur case `planmanobraBeanArrayList`) have certain value for attribute X, when `getView()` is called it render/init/reuse views to create proper list for you, reading data from the model, in this case it will be the data already in the model, not the one entered (altered) in the editText, what you need to do is to update the model data once the editText is changed, so next time this item is rendered, it will populate using new data in model – Yazan Mar 13 '16 at 09:20
  • @Yazan so you mean to say that in textwatcher I should set the value again in planmanobraBeanArrayList? – Vivek Mishra Mar 13 '16 at 10:00
  • yup, it could be a way, the idea is to capture updated values from EditText(s) and update the corresponding value of that item in the data-list or array. – Yazan Mar 13 '16 at 10:03
  • ok I will try that – Vivek Mishra Mar 13 '16 at 10:04

1 Answers1

1

Finally I got it working using Focus Change Listener and adding one more parameter to the existing arraylist. Using another list or Hashmap didn't worked for me. So as suggested by Yazan I added it in my arraylist and is working now. Here is the code what I have now

 holder.Cantidad.setText(planmanobraBeanArrayList.get(position).getEditext());
        final ViewHolder finalHolder = holder;
        holder.Cantidad.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                if (!hasFocus)
                {
                    if (!finalHolder.Cantidad.getText().toString().equals(""))
                    {
                        planmanobraBeanArrayList.get(position).setEditext(finalHolder.Cantidad.getText().toString());
                    }else {
                        planmanobraBeanArrayList.get(position).setEditext("");
                    }
                }

            }
        });

Thanks for everyone help

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84