0

I had tried many solutions and tutorials but none of them had solved my problem. I want to implement an editable listview but when i write in the textbox it's value copies to other textboxes also, sometimes on scrolling and sometimes without scrolling the list. Any help will be greatly appreciated.

 @Override
 public View getView( final int position, View convertView, ViewGroup parent) {
  final   ViewHolder holder;
  if (convertView == null) {
        convertView = inflater.inflate(R.layout.productslistviewadapter, parent, false);

        holder = new ViewHolder();
        holder.tvdrCode = (TextView) convertView.findViewById(R.id.tvname);
        holder.tvDrName = (TextView) convertView.findViewById(R.id.tvprodpack);
        holder.tvterrcode= (TextView) convertView.findViewById(R.id.textView3);
        holder.caption = (EditText)convertView.findViewById(R.id.editText1);
        convertView.setTag(holder);

    } 
 else {
        holder = (ViewHolder) convertView.getTag();
    }

    Products p = prodList.get(position);
    holder.tvdrCode.setText(p.getDocCode());
    holder.tvDrName.setText(p.getDocName());
    holder.tvterrcode.setText(p.getAdr());

    holder.caption.setTag(position);
    holder.caption.setText(p.getCaption());
    int tag_position=(Integer) holder.caption.getTag();
    holder.caption.setId(tag_position); 

    holder.caption.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start,int before, int count) {

             final int  position2 = holder.caption.getId();
             final EditText Caption = (EditText) holder.caption;
             if(Caption.getText().toString().length()>0){
             prodList.get(position2).setCaption(Caption.getText().toString());

            }
        }

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

        @Override
        public void afterTextChanged(Editable s) {

            }

        }
    });  
        return convertView;
 } 
 static class ViewHolder {
 TextView code;
 TextView Name;
 EditText caption;
 }} 
user3751512
  • 23
  • 1
  • 4
  • You are using addTextChangedListener on every getView call. Are you sure you are not adding multiple TextWatchers on the captions by doing this? I guess it should be only one TextWatcher each? – daemmie Jul 13 '15 at 08:31
  • I don't know about this, what is the other way to call it. – user3751512 Jul 13 '15 at 09:54
  • 1
    This might help you: http://stackoverflow.com/questions/6270484/how-to-remove-all-listeners-added-with-addtextchangedlistener – daemmie Jul 13 '15 at 10:02

0 Answers0