请帮助我摆脱这个问题::::我已经实现了视图持有者模式,这意味着重用项目。每次我重新加载应用程序
公共类NavDrawerListAdapter扩展了BaseAdapter {
private Context context;
ImageLoader mLoader;
LayoutInflater inflater;
DisplayImageOptions options;
private ArrayList<NavDrawerItem> navDrawerItems;
public NavDrawerListAdapter(Context context,
ArrayList<NavDrawerItem> navDrawerItems) {
this.context = context;
this.navDrawerItems = navDrawerItems;
// this.inflater = (LayoutInflater) context
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mLoader = mLoader;
File cacheDir = StorageUtils.getOwnCacheDirectory(context,
"your folder");// for caching
// Get singletone instance of ImageLoader
mLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir))
// You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging().build();
// Initialize ImageLoader with created configuration. Do it once.
mLoader.init(config);
options = new DisplayImageOptions.Builder()
// display stub image untik image is loaded
.cacheInMemory().cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20)).build();
}
@Override
public int getCount() {
return navDrawerItems.size();
}
@Override
public Object getItem(int position) {
return navDrawerItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater infl = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = infl
.inflate(R.layout.drawer_list_item, parent, false);
holder = new ViewHolder();
assert convertView != null;
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
mLoader.displayImage(
"http://pin.muction.com/app/webroot/img/b0e485evideocon_logo.jpg",
holder.imageView, options);
new DownloadImageTask(holder.imageView)
.execute(OperatorsActivity.img_path[position]);
return convertView;
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
private final WeakReference<ImageView> imageViewReference;
public DownloadImageTask(ImageView bmImage) {
imageViewReference = new WeakReference<ImageView>(bmImage);
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Log.i("path", urldisplay);
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(
"http://pin.muction.com/app/webroot/img/" + urldisplay)
.openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
if (imageViewReference != null && result != null) {
bmImage = imageViewReference.get();
if (bmImage != null) {
bmImage.setImageBitmap(result);
}
}
}
}
}