简体   繁体   English

方法getBitmapFromMemCache(String)未定义

[英]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.

相关问题 NoMethodError(“”:String的未定义方法“ permit!”): - NoMethodError (undefined method `permit!' for “ ”:String): 方法setText(String)未定义为TimePicker - The method setText(String) is undefined for TimePicker AutoCompleteTextView-未为类型String定义方法setText(String) - AutoCompleteTextView - The method setText(String) is undefined for the type String 对于PendingIntent类型,方法putExtra(String,String)未定义 - The method putExtra(String, String) is undefined for the type PendingIntent 对于Intent类型,未定义方法putStringExtra(String,String) - The method putStringExtra(String, String) is undefined for the type Intent 在Android中,类型String的方法getString(String)未定义 - The method getString(String) is undefined for the type String in Android 方法openOrCreateDatabase(String,int,null)未定义 - The method openOrCreateDatabase(String, int, null) is undefined 对于类型MainActivity,未定义方法getParcelableArrayList(String) - The method getParcelableArrayList(String) is undefined for the type MainActivity 对于TweetListAdaptor类型,未定义方法getSystemService(String) - The method getSystemService(String) is undefined for the type TweetListAdaptor 对于MyReciever类型,未定义方法getsystemservice(string) - the method getsystemservice(string) is undefined for the type MyReciever
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM