0
현재 Zonghai-li의 android-http-image-manager를 사용하고 있지만 현재 직면하고있는 문제는 이미지를 다운로드 할 때 그 순간 그리드보기 목록을 스크롤하면 이미지가 다른 그리드 셀에 표시됩니다. 누군가가이 문제로 나를 도울 수 있습니까 ..?gridview에서 이미지의 비동기 로딩
package com.syncusup.list.adapters;
import java.io.File;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;
import com.syncusup.R;
import com.syncusup.UILApplication;
import com.syncusup.httpimageloader.HttpImageManager;
import com.syncusup.model.VCard;
import com.syncusup.utils.SyncLocalDatabase;
public class LocalContactsAdapter extends ArrayAdapter<VCard> {
private LayoutInflater mInflater;
private ArrayList<VCard> mOriginalList;
private ArrayList<VCard> mContactList;
private HttpImageManager mHttpImageManager;
private MyFilter mFilter;
private Context mContext;
private File aFileToCheck;
public LocalContactsAdapter(Context iContext, ArrayList<VCard> iVcardsArray) {
super(iContext, R.layout.localcontacts_row, iVcardsArray);
this.mContactList = new ArrayList<VCard>();
this.mContactList.addAll(iVcardsArray);
this.mOriginalList = new ArrayList<VCard>();
this.mOriginalList.addAll(iVcardsArray);
this.mContext = iContext;
mHttpImageManager = ((UILApplication)((Activity)mContext).getApplication())
.getHttpImageManager();
}
private class ViewHolder {
public TextView aContactName;
public TextView aContact;
public ImageView aContactImage;
}
@Override
public Filter getFilter() {
if (mFilter == null) {
mFilter = new MyFilter();
}
return mFilter;
}
@Override
public int getPosition(VCard iItem) {
return super.getPosition(iItem);
}
@Override
public int getCount() {
return mContactList.size();
}
@Override
public VCard getItem(int iPosition) {
return mContactList.get(iPosition);
}
@Override
public long getItemId(int iPosition) {
return iPosition;
}
@Override
public View getView(final int iPosition, View iConvertView, ViewGroup iParent) {
final ViewHolder aHolder;
aFileToCheck = new File(Environment.getExternalStorageDirectory() + "/SyncUsUp/",
SyncLocalDatabase.computeHashedName(mContactList.get(iPosition).getID()));
if (iConvertView == null || iConvertView.getTag() == null) {
// default layout inflater
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
iConvertView = mInflater.inflate(R.layout.localcontacts_row, null);
aHolder = new ViewHolder();
aHolder.aContactName = (TextView)iConvertView.findViewById(R.id.tvMyContactName);
aHolder.aContact = (TextView)iConvertView.findViewById(R.id.tvMyContact);
aHolder.aContactImage = (ImageView)iConvertView.findViewById(R.id.ivContact);
iConvertView.setTag(aHolder);
} else {
aHolder = (ViewHolder)iConvertView.getTag();
}
ImageView aImageView = aHolder.aContactImage;
aImageView.setImageResource(R.drawable.contact_box_blanktile);
try {
if (mContactList.get(iPosition).getPhoto() != null) {
Bitmap aBitmap = mHttpImageManager.loadImage(new HttpImageManager.LoadRequest(Uri
.parse(mContactList.get(iPosition).getPhoto().getUrl()), aImageView));
if (aBitmap != null) {
aImageView.setImageBitmap(aBitmap);
}
} else if (aFileToCheck.exists()) {
Bitmap aBitmap = mHttpImageManager.loadImage(new HttpImageManager.LoadRequest(Uri
.parse(mContactList.get(iPosition).getID()), aImageView));
if (aBitmap != null) {
aImageView.setImageBitmap(aBitmap);
}
}
} catch (Exception iException) {
iException.printStackTrace();
}
if (mContactList.get(iPosition).getFullName() != null) {
aHolder.aContactName.setText(mContactList.get(iPosition).getFullName());
} else {
aHolder.aContactName.setText("No Name");
}
return iConvertView;
}
private class MyFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence iConstraint) {
FilterResults aResult = null;
try {
iConstraint = iConstraint.toString().toLowerCase();
aResult = new FilterResults();
if (iConstraint != null && iConstraint.toString().length() > 0) {
ArrayList<VCard> aFilteredItems = new ArrayList<VCard>();
for (int i = 0, l = mOriginalList.size(); i < l; i++) {
VCard aList = mOriginalList.get(i);
if (aList.getFullName() != null) {
if (aList.getFullName().toString().toLowerCase().contains(iConstraint))
aFilteredItems.add(aList);
}
}
aResult.count = aFilteredItems.size();
aResult.values = aFilteredItems;
} else {
synchronized (this) {
aResult.values = mOriginalList;
aResult.count = mOriginalList.size();
}
}
} catch (Exception iException) {
iException.printStackTrace();
}
return aResult;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence iConstraint, FilterResults iResults) {
try {
mContactList = (ArrayList<VCard>)iResults.values;
notifyDataSetChanged();
clear();
for (int i = 0, l = mContactList.size(); i < l; i++)
add(mContactList.get(i));
notifyDataSetInvalidated();
} catch (Exception iException) {
iException.printStackTrace();
}
}
}
}
동일한 라이브러리를 제안 할 수 있습니까? –
Check Aquery : http://code.google.com/p/android-query/ –
감사합니다. @Eldhose M Babu이 나를 멋진 라이브러리로 안내해주었습니다. –