系统似乎正在回收视图,直到它在我的列表视图中加载正确位置的视图,导致重复的图像和文本几秒钟。任何人都可以帮忙吗?
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
Log.d("position",""+position);
if(v==null){
LayoutInflater inflater = LayoutInflater.from(mContext);
v = inflater.inflate(R.layout.layout_appinfo, null);
holder = new ViewHolder();
holder.ivAppIcon = (ImageView)v.findViewById(R.id.ivIconApp);
holder.tvAppName = (TextView)v.findViewById(R.id.tvNameApp);
holder.progress = (ProgressBar)v.findViewById(R.id.progress_spinner);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.ivAppIcon.setImageDrawable(null);
holder.tvAppName.setText(null);
holder.progress.setVisibility(View.VISIBLE);
holder.ivAppIcon.setVisibility(View.GONE);
// Using an AsyncTask to load the slow images in a background thread
new AsyncTask<ViewHolder, Void, Drawable>() {
private ViewHolder v;
private ResolveInfo entry = (ResolveInfo) mListAppInfo.get(position);
@Override
protected Drawable doInBackground(ViewHolder... params) {
v = params[0];
return entry.loadIcon(mPackManager);
}
@Override
protected void onPostExecute(Drawable result) {
super.onPostExecute(result);
// If this item hasn't been recycled already, hide the
// progress and set and show the image
v.progress.setVisibility(View.GONE);
v.ivAppIcon.setVisibility(View.VISIBLE);
v.ivAppIcon.setImageDrawable(result);
v.tvAppName.setText(entry.loadLabel(mPackManager));
}
}.execute(holder);
return v;
}
static class ViewHolder {
TextView tvAppName;
ImageView ivAppIcon;
ProgressBar progress;
//int position;
}
就好像位置设置错误了几秒钟。