in my custom ArrayAdapter, I am using the view holder pattern, inside the getView()
method I have a TextChangedListener()
to which I am doing this:
List<Child> children;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
List<Adult> converted = Converter.convert(children);
clear();
addAll(converted);
notifyDataSetChanged();
}
@Override
public void clear() {
children.clear();
}
@Override
public void addAll(Collection<? extends Currency> collection) {
children.addAll(collection);
}
I set the children list in the constructor, so please don't worry about that being null or anything, during debug, it has data, the converted
list has data, the clear method is called and both lists at that point are cleared...could someone shed some light as to why?
If you want to just clear a particular list just use
converted.clear();
or
children.clear();
Both are getting cleared due to converted being a reference to children. To avoid this you can use
List<Adult> converted = new ArrayList<>();
converted.addAll(Converter.convert(children);
and continue to call
clear();
However, it should be noted that when you are calling
clear();
You are actually calling it on the entire adapter, which clears the dataset. Which is why I said you should specify which list you are trying to clear, but I would also use the ArrayList<>() declaration from above with .addAll()