I am using an Expandable listview in Android and having huge problems with interactive EditTexts within the child items due to Android's recycle policy.
I was wondering if I could somehow disable this recycling (there won't be too many elements there, so performance shouldn't be an issue)?
The problem is that there are duplicates in the EditTexts, i.e. if I type in something in the first EditText, it is possible that in some other EditText the same text appears, or if I collapse and expand a group, the strings in the EditTexts often get mixed up.
Following my code:
EDIT:
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildItem item = getChild(groupPosition, childPosition);
String comment = "";
state = getStatelist().get(groupPosition);
if (convertView == null) {
holder = new ChildHolder();
convertView = inflater.inflate(R.layout.childitem_list_item, parent, false);
holder.title = (EditText) convertView.findViewById(R.id.textTitle);
convertView.setTag(holder);
} else {
holder = (ChildHolder) convertView.getTag();
}
if(state.commentList != null){
holder.title.setText(state.commentList[childPosition]);
}
else{
holder.title.setText("");
}
holder.title.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
state = getStatelist().get(groupPosition);
state.commentList[childPosition] = s.toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
public class States {
public String code = "";
public String name = "";
public String[] commentList;
}