Capturing TextChanged events inside a list in Android

I have a ListView containing an EditText. I want to capture the textchanged event of this text field and update the other columns.

Inside my customAdapter, I did it

public View getView(int position, View inView, ViewGroup parent) { View v = inView; if (v == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.cartlistview, null); } EditText edQty = (EditText) v.findViewById(R.id.cartProductQuantity); edQty.addTextChangedListener(new QtyChangedWatcher(position, v)); } 

The event fires on its own, even when the user has not changed anything. Moreover, when the user changes the input only for the first line, the event is fired, but for all text fields in the list.

Am I doing something wrong?

thanks

+4
source share
1 answer

try the following:

 public View getView(int position, View inView, ViewGroup parent) { View v = inView; if (v == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.cartlistview, null); EditText edQty = (EditText) v.findViewById(R.id.cartProductQuantity); edQty.addTextChangedListener(new QtyChangedWatcher(position, v)); } } 

(move your addTextChangedListener to the if condition)

0
source

Source: https://habr.com/ru/post/1394850/


All Articles