你好我搜索SO和尽我所能,但不能让它work..i有一个列表视图我在哪里用影像手机通讯录加载。下面是我的代码安卓:列表视图的问题,图像被错误地分配
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
}
}
的问题是,我得到的名单,但图像加载当我开始滚动,滚动只图像之后是稳定的,并在右position..not知道从哪里IAM做错了,我想图像应当列表加载和图像后装应在正确的位置...任何帮助表示赞赏
可以详细说明您的答案......您的意思是分配空白图片或原始联系人图片......? – teekib
不,只要做点什么。你在if语句中的代码需要分配一些东西。我会编辑我的答案。 – Heinrisch