[英]The method getBitmapFromMemCache(String) is undefined
I'm following the tutorial from http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html , but I can't find getBitmapFromMemCache(String) method anywhere!! 我正在从http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html阅读本教程,但在任何地方都找不到getBitmapFromMemCache(String)方法!
In what class I can find it? 我在什么班上能找到它?
It's a custom method they implemented. 这是他们实施的自定义方法。 Just have a look at the first listing on the page you linked:
只需查看链接页面上的第一条清单即可:
private LruCache<String, Bitmap> mMemoryCache;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Get max available VM memory, exceeding this amount will throw an
// OutOfMemory exception. Stored in kilobytes as LruCache takes an
// int in its constructor.
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
// Use 1/8th of the available memory for this memory cache.
final int cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getByteCount() / 1024;
}
};
...
}
public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}
public Bitmap getBitmapFromMemCache(String key) {
return mMemoryCache.get(key);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.