嗨,我搜索了 SO 并尽力而为,但无法使其正常工作..我有一个列表视图,我正在加载带有图像的电话联系人。下面是我的代码
public ProfileAdapter(Activity activity, int textViewResourceId, List<Profile> listCont,int renderer, String profileType) {
super(activity, textViewResourceId, listCont);
this.renderer = renderer;
this.listCont = listCont;
this.activity = activity;
this.profileType = profileType;
}
public class ViewHolder {
View rowView;
public TextView textEmailId= null;
public TextView textContNo= null;
public TextView text= null;
public ImageView photo= null;
public int position;
}
@Override
public View getView( int position, View convertView, ViewGroup parent) {
//View view = convertView;
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(renderer, null);
holder = new ViewHolder(convertView);
holder.text = (TextView) convertView.findViewById(R.id.name);
holder.textContNo = (TextView) convertView.findViewById(R.id.contactno);
holder.textEmailId = (TextView) convertView.findViewById(R.id.emailId);
holder.photo = (ImageView ) convertView.findViewById(R.id.quickContactBadge1);
convertView.setTag(holder);
}
else {
holder =(ViewHolder) convertView.getTag();
holder.position = position;
Profile contact = listCont.get(position);
holder.text.setText(contact.getName());
ImageView photo = (ImageView ) convertView.findViewById(R.id.quickContactBadge1);
photo.setTag(contact.getMobileNo());
photo.setImageResource(R.drawable.stub_image);
new LoadImage(photo).execute(contact.getMobileNo());
}
return convertView;
}
class LoadImage extends AsyncTask<String, Void, Bitmap>{
// private final WeakReference<ImageView> viewReference;
private ImageView img;
public LoadImage(ImageView img) {
//viewReference = new WeakReference<ImageView>( view );
this.img=img;
}
@Override
protected Bitmap doInBackground(final String... params) {
new QuickContactHelper(activity, img, (String) params[0]).addThumbnail();
return null;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
// nothing
}
}
问题是,我正在获取列表,但是当我开始滚动时,图像正在加载,只有在滚动图像稳定且位置正确之后,我才知道我在哪里做错了,我希望在列表加载后加载图像和图像应该在正确的位置......任何帮助表示赞赏