I have an Android application with an customized adapter that extends Cursor Adapter.
I overrided bindView and newview methods of CursorAdapter. Each of my ListView row contains an EditText. When I enter some text in EditText and scrolldown the ListView the content of the EditText text is moved to another EditText.
Can anyone help me in sorting out this issue to how to prevent EditText from reused its content when ListView is scrolled down.
Thanks in Advance,
Here is the code:
private class AddScreenArrayAdapter extends ArrayAdapter<AddScreenItems>{
ViewHolder viewHolder = null;
public String[] holder_values;
public AddScreenArrayAdapter(Context context, int textViewResourceId,
List<AddScreenItems> objects) {
super(context, textViewResourceId, objects);
holder_values = new String[objects.size()];
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.additem_row, null);
viewHolder = new ViewHolder();
viewHolder.label = (TextView) v.findViewById(R.id.label_add_item);
viewHolder.dbName=(TextView)v.findViewById(R.id.dbtable_name);
viewHolder.value = (EditText) v.findViewById(R.id.value_add_item);
viewHolder.value.addTextChangedListener(new TextWatcher()
{
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
holder_values[viewHolder.ref]= arg0.toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
// TODO Auto-generated method stub
}
});
v.setTag(viewHolder);
}
else{
viewHolder = (ViewHolder) v.getTag();
}
AddScreenItems addScreenItems = addScreenItemsList.get(position);
if(addScreenItems!=null)
{
viewHolder.label.setText(addScreenItems.labelname);
viewHolder.dbName.setText(addScreenItems.databaseTableName);
// viewHolder.ref = position;
if (holder_values[position] != null)
{
viewHolder.value.setText(holder_values[position]);
}
else {
viewHolder.value.setText("");
}
}
return v;
}
}
static class ViewHolder {
public TextView label;
public EditText value;
public TextView dbName;
int ref;
}