新手getview 本帖最后由 lenovo9991 于 2012-08-20 17:01:56 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 方法是更改数组,然后adapter notifydatachange 我在activity里是这样调用的adapter = new ImageAndTextListAdapter(this, imageAndTexts, listv, icount); adapter.notifyDataSetChanged();listv.setAdapter(adapter); 另外getview 里面的position第一次调用0,1第二次是0,1,2,3第三次是0,1,2,3,4,5每次都从0开始 if (cachedImage == null) { imageView.setImageResource(R.drawable.ic_launcher); }else{ imageView.setImageDrawable(cachedImage); }我发现 cachedImage 总是null所以一直执行imageView.setImageResource(R.drawable.ic_launcher); 不知为什么?异步类如下:public class AsyncImageLoader { // 为了加快速度,在内存中开启缓存(主要应用于重复图片较多时,或者同一个图片要多次被访问,比如在ListView时来回滚动) public Map<String, SoftReference<Drawable>> imageCache = new HashMap<String, SoftReference<Drawable>>(); private ExecutorService executorService = Executors.newFixedThreadPool(5); // 固定五个线程来执行任务 private final Handler handler = new Handler(); /** * * @param imageUrl * 图像url地址 * @param imageCallback * 回调接口 * @return 返回内存中缓存的图像,第一次加载返回null */ public Drawable loadDrawable(final String imageUrl, final zz.nice.wife.AsyncImageLoader.ImageCallback imageCallback) { // 如果缓存过就从缓存中取出数据 if (imageCache.containsKey(imageUrl)) { SoftReference<Drawable> softReference = imageCache.get(imageUrl); System.out.println("执行1"); if (softReference.get() != null) { return softReference.get(); } } // 缓存中没有图像,则从网络上取出数据,并将取出的数据缓存到内存中 executorService.submit(new Runnable() { public void run() { try { final Drawable drawable = loadImageFromUrl(imageUrl); imageCache.put(imageUrl, new SoftReference<Drawable>( drawable)); handler.post(new Runnable() { public void run() { imageCallback.imageLoaded(drawable, imageUrl); } }); } catch (Exception e) { throw new RuntimeException(e); } } }); return null; } // 从网络上取数据方法 protected Drawable loadImageFromUrl(String imageUrl) { try { // 测试时,模拟网络延时,实际时这行代码不能有 //SystemClock.sleep(2000); return Drawable.createFromStream(new URL(imageUrl).openStream(), "image.png"); } catch (Exception e) { throw new RuntimeException(e); } } // 对外界开放的回调接口 public interface ImageCallback { // 注意 此方法是用来设置目标对象的图像资源 public void imageLoaded(Drawable imageDrawable); }}蓝色部分一直是false 未缓存 调用图片类里面的if (imageCache.containsKey(imageUrl)) { SoftReference<Drawable> softReference = imageCache.get(imageUrl); System.out.println("执行1"); if (softReference.get() != null) { return softReference.get(); }}这段也未执行 android 4.03 wifi 移植问题 android 选项卡 TabHost的问题 求助:怎么能让TextView内容自动滚屏 请教类似“我查查”软件的支持无自动对焦手机的条码识别,是如何实现的? android2.3打开字符设备节点失败!!! android消息推送问题,急求大侠赐教!!! Android环境构建时出现的问题!!!焦头烂额了,在线等,急需解决 应用移到sd卡 安卓HTTP请求sign参数 json解析问题 anroid怎么30秒连接一个服务器 关于解锁屏幕后引发的问题
adapter = new ImageAndTextListAdapter(this, imageAndTexts, listv, icount);
adapter.notifyDataSetChanged();
listv.setAdapter(adapter); 另外getview 里面的position第一次调用
0,1
第二次是
0,1,2,3
第三次是
0,1,2,3,4,5每次都从0开始
if (cachedImage == null) {
imageView.setImageResource(R.drawable.ic_launcher);
}else{
imageView.setImageDrawable(cachedImage);
}
我发现 cachedImage 总是null所以一直执行
imageView.setImageResource(R.drawable.ic_launcher);
不知为什么?异步类如下:
public class AsyncImageLoader {
// 为了加快速度,在内存中开启缓存(主要应用于重复图片较多时,或者同一个图片要多次被访问,比如在ListView时来回滚动)
public Map<String, SoftReference<Drawable>> imageCache = new HashMap<String, SoftReference<Drawable>>();
private ExecutorService executorService = Executors.newFixedThreadPool(5); // 固定五个线程来执行任务
private final Handler handler = new Handler();
/**
*
* @param imageUrl
* 图像url地址
* @param imageCallback
* 回调接口
* @return 返回内存中缓存的图像,第一次加载返回null
*/
public Drawable loadDrawable(final String imageUrl,
final zz.nice.wife.AsyncImageLoader.ImageCallback imageCallback) {
// 如果缓存过就从缓存中取出数据
if (imageCache.containsKey(imageUrl)) {
SoftReference<Drawable> softReference = imageCache.get(imageUrl);
System.out.println("执行1");
if (softReference.get() != null) {
return softReference.get();
}
}
// 缓存中没有图像,则从网络上取出数据,并将取出的数据缓存到内存中
executorService.submit(new Runnable() {
public void run() {
try {
final Drawable drawable = loadImageFromUrl(imageUrl);
imageCache.put(imageUrl, new SoftReference<Drawable>(
drawable));
handler.post(new Runnable() {
public void run() {
imageCallback.imageLoaded(drawable, imageUrl);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
return null;
} // 从网络上取数据方法
protected Drawable loadImageFromUrl(String imageUrl) {
try {
// 测试时,模拟网络延时,实际时这行代码不能有
//SystemClock.sleep(2000); return Drawable.createFromStream(new URL(imageUrl).openStream(),
"image.png"); } catch (Exception e) {
throw new RuntimeException(e);
}
} // 对外界开放的回调接口
public interface ImageCallback {
// 注意 此方法是用来设置目标对象的图像资源
public void imageLoaded(Drawable imageDrawable);
}}蓝色部分一直是false 未缓存
if (imageCache.containsKey(imageUrl)) {
SoftReference<Drawable> softReference = imageCache.get(imageUrl);
System.out.println("执行1");
if (softReference.get() != null) {
return softReference.get();
}
}
这段也未执行