View Caching

Android Extensions adds a hidden cache function and storage field to each container. The defualt cache is a Hashmap.

in the following example findViewById() is called once

class MyActivity : Activity()

fun MyActivity.a() { 
    textView.text = "Hidden view"
    textView.visibility = View.INVISIBLE
}

The cache stragegy can be configured by: build.gradle

androidExtensions {
    defaultCacheImplementation = "HASH_MAP" // also SPARSE_ARRAY, NONE
}

or by @ContainerOptions annotation

import kotlinx.android.extensions.ContainerOptions

@ContainerOptions(cache = CacheImplementation.NO_CACHE)
class MyActivity : Activity()

fun MyActivity.a() { 
    // findViewById() will be called twice
    textView.text = "Hidden view"
    textView.visibility = View.INVISIBLE
}

results matching ""

    No results matching ""