So I have a ListView
for which I made a custom adapter using a layout with a TextView
and an EditText
.
For the EditText
I use a List<String>
to store the content of all the EditTexts in the list. I do this using a OnFocusChangeListener(
).
The problem I'm having is that when an EditText
is focused and I scroll enough so it's view is recycled, I loose the content of it, but if I click away so it becomes unfocused before scrolling it out of visible area it works fine.
I was thinking of saving the content of it when it is recycled, or destroyed, so that is why I'm asking what method is called when it is scrolled out of visible area. Or I can do this when the list starts scrolling, if there is a method I can use for this.
Here is the getView
method from my custom adapter:
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView == null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_item_edit_content, null);
holder.input = (EditText) convertView.findViewById(R.id.input);
holder.title = (TextView) convertView.findViewById(R.id.rowName);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(columnNames.get(position));
holder.input.setText(values.get(position));
holder.input.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus)
{
values.set(position, holder.input.getText().toString());
}
}
});
return convertView;
}
private class ViewHolder
{
EditText input;
TextView title;
}