我有一个包含一个textview
和一个edit text
的listview
,每一行都有。如果我在一个编辑文本字段中设置一个值,然后向下滚动,我会在其他一些编辑文本字段中获得该输入字段的重复值。如何解决这个问题?
我的适配器类如下所示:
public class CustomAdapter extends ArrayAdapter<String> {
private Context context;
private String[] names;
ViewHolder holder;
static class ViewHolder {
public TextView text;
public EditText editText;
}
public CustomAdapter(Context context, int textViewResourceId, String[] names) {
super(context, textViewResourceId, names);
this.context = context;
this.names = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_design, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.textView1);
holder.editText = (EditText) convertView.findViewById(R.id.editText1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String s = names[position];
holder.text.setText(s);
return convertView;
}
}
我参考了以下链接: Listview重复操作,Android listview滚动时会出现重复的项目