我做了很多研究,我和一所大学花了几个小时试图弄清楚这一点。冒着作为副本关闭的风险,我无处可去!我遇到了很多重复 ListView 的解决方案,并且我了解如何重用视图(使用 convertView)等。但是我似乎无法找到我的问题来自哪里。该问题具有相同的典型症状,如果我在列表中的一个 EditText 中输入文本,则向下 5-6 项...相同的文本在那里!
我在getView(...)
下面附上了我的代码以帮助你们帮助我,但如果您需要其他任何东西,请告诉我。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// inflator for all the views
LayoutInflater vi = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// the object where I will be getting my display data
final Object currentItem = drawItems.get(position);
// standard adapter/view stuff
View v = convertView;
ViewHolder holder = null;
int type = getItemViewType(position);
if (v == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ROW:
v = vi.inflate(R.layout.row_textview, null);
// get my views
holder.editText= (EditText) v
.findViewById(R.id.line_edittextview);
break;
case TYPE_SUMMARY:
v = vi.inflate(R.layout.row_summary, null);
break;
}
Log.i(TAG, "Convert View Tag being set: " + holder);
v.setTag(holder);
} else {
Log.i(TAG,
"Getting holder from Convert View Tag: " + v.getTag());
holder = (ViewHolder) v.getTag();
}
switch (type) {
case TYPE_ROW:
Log.i(TAG, "Holder in use: " + holder);
holder.editText.setText("Line " + (position + 1));
break;
case TYPE_SUMMARY:
break;
}
return v;
}
@Override
public int getItemViewType(int position) {
return TYPE_BETSLIP;
}
@Override
public int getViewTypeCount() {
return 2;
}
谢谢!:-)