我有一个带有自定义适配器的 Android 应用程序,该适配器扩展了光标适配器。
我重写了 CursorAdapter 的 bindView 和 newview 方法。我的每个 ListView 行都包含一个 EditText。当我在 EditText 中输入一些文本并向下滚动 ListView 时,EditText 文本的内容将移动到另一个 EditText。
任何人都可以帮我解决这个问题,以便在向下滚动 ListView 时防止 EditText 重用其内容。
提前致谢,
这是代码:
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;
}