EditText loses content on scroll in ListView

you should try in this way as below:

if (convertView == null) {

        holder = new ViewHolder();

        LayoutInflater vi = (LayoutInflater)    
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.element_in_game, null);

        holder.scoreToUpdate = (EditText) convertView
                .findViewById(R.id.elementUpdateScore);


        convertView.setTag(holder);

    } else {

        holder = (ViewHolder) convertView.getTag();

    }
   //binding data from array list
   holder.scoreToUpdate.setText(scoresToUpdate[position]);
   holder.scoreToUpdate.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start,
                    int before, int count) {
                //setting data to array, when changed
                scoresToUpdate[position] = s.toString();
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start,
                    int count, int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    return convertView;
}

Explanation:
Recycling behavior of ListView, actually erase all data bind with its Row Item, when go out of vision.
So every new row coming in in vision from whatever direction you need to bind data again.
Also, when EditText text change you have to keep values also in some data structure, so later on again row data binding you can extract data for position.
You can use, array ArrayList for keeping edittext data, and also can use to bind data.

Similar behavior use in Recyclerview Adapter, behind logic you need to know about data binding of row data of adapters.

Leave a Comment