我扩展了基本适配器 --- 我遇到了一些奇怪的问题...当我滚动此列表视图时 -- 我的最后一个项目被第一个项目替换,下次当我滚动时 - 另一个项目等等......有时它是正确的。 .为什么这段代码会发生这种情况?
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// sets the view onto list view
LinearLayout rowLayout = null;
System.out.println("getView " + position + " " + convertView);
rowLayout = (LinearLayout) mInflater.inflate(
R.layout.apps_list_row_items, parent, false);
if (convertView == null) {
// inflating the row
vh.mAppIcon = (ImageView) rowLayout.findViewById(R.id.icon);
vh.mAppName = (TextView) rowLayout.findViewById(R.id.application);
vh.mAppHint = (TextView) rowLayout.findViewById(R.id.hint);
mDownloadButton = (Button) rowLayout.findViewById(R.id.download);
mDownloadButton.setFocusable(false);
} else {
// convertView.getTag();
rowLayout = (LinearLayout) convertView;
}
// convertView.getTag();
// On Click of the download button which triggers an async to download
// the file.
mIcon = mAppIconMapList.get(position);
System.out.println("Icon " + mIcon);
mCurrentApplication = mAvaiableApps.get(position);
System.out.println("Current App " + mCurrentApplication);
vh.mAppIcon.setImageBitmap(mIcon.get(mCurrentApplication));
vh.mAppName.setText(mCurrentApplication.replace(".apk", ""));
vh.mAppHint.setText("Click here to view Description");
return rowLayout;
}
问题是列表适配器有时会重用行。如果您想解决此问题,请删除以下内容:
if (convertView == null) { <----remove
//code
} <----remove
else{ <----remove
... <----remove
} <----remove
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)