ListView的杂乱地堆在滚动 [英] ListView Jumbled on scroll
本文介绍了ListView的杂乱地堆在滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经扩展底座适配器---我有一些奇怪的问题......当我滚动列表视图这个 - 我的最后一个项与第一项,下一次更换时我滚动 - 另一个项目和所有..它的某个时候是正确的。为什么它的这个code发生了什么?
@覆盖
公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
//设置视图到列表视图
LinearLayout中的RowLayout = NULL; 的System.out.println(getView+位置++ convertView);
的RowLayout =(的LinearLayout)mInflater.inflate(
R.layout.apps_list_row_items,父母,假);
如果(convertView == NULL){
//充气行 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 =(按钮)rowLayout.findViewById(R.id.download);
mDownloadButton.setFocusable(假); }其他{
// convertView.getTag();
的RowLayout =(LinearLayout中)convertView;
}
// convertView.getTag(); //在点击下载按钮触发异步下载的
// 文件。
米康= mAppIconMapList.get(位置);
的System.out.println(图标+米康);
mCurrentApplication = mAvaiableApps.get(位置);
的System.out.println(当前应用程序+ mCurrentApplication);
vh.mAppIcon.setImageBitmap(mIcon.get(mCurrentApplication));
vh.mAppName.setText(mCurrentApplication.replace(),APK);
vh.mAppHint.setText(点击此处查看说明); 返回的RowLayout;
}
解决方案
您的 getView 方式看起来有点可疑,尝试如下更改它:
@覆盖
公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
//设置视图到列表视图 ViewHolder VH =无效;
的System.out.println(getView+位置); 如果(convertView == NULL){
//充气行
LinearLayout中的RowLayout =(的LinearLayout)mInflater.inflate(
R.layout.apps_list_row_items,父母,假); 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 =(按钮)rowLayout.findViewById(R.id.download);
mDownloadButton.setFocusable(假); convertView.setTag(VH); }其他{
VH =(ViewHolder)convertView.getTag();
}
//在点击下载按钮触发异步下载的
// 文件。
米康= mAppIconMapList.get(位置);
的System.out.println(图标+米康);
mCurrentApplication = mAvaiableApps.get(位置);
的System.out.println(当前应用程序+ mCurrentApplication);
vh.mAppIcon.setImageBitmap(mIcon.get(mCurrentApplication));
vh.mAppName.setText(mCurrentApplication.replace(),APK);
vh.mAppHint.setText(点击此处查看说明); 返回convertView;
}
i have extended Base Adapter --- i am having some strange problem... when i scroll this listview -- my last items are replaced with first item and next time when i scroll - another item and all.. sometime it is correct.. why its happening with this code ?
@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;
}
解决方案
Your getView method looks a little suspicious, try changing it as below:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// sets the view onto list view
ViewHolder vh = null;
System.out.println("getView " + position);
if (convertView == null) {
// inflating the row
LinearLayout rowLayout = (LinearLayout) mInflater.inflate(
R.layout.apps_list_row_items, parent, false);
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);
convertView.setTag(vh);
} else {
vh = (ViewHolder) 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 convertView;
}
这篇关于ListView的杂乱地堆在滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文