Google 致力于为黑人社区推动种族平等。查看具体举措

ViewTreeViewModelStoreOwner

public class ViewTreeViewModelStoreOwner
extends Object

java.lang.Object
   ↳ androidx.lifecycle.ViewTreeViewModelStoreOwner


Accessors for finding a view tree-local ViewModelStoreOwner that allows access to a ViewModelStore for the given view.

Summary

Public methods

static ViewModelStoreOwner get(View view)

Retrieve the ViewModelStoreOwner associated with the given View.

static void set(View view, ViewModelStoreOwner viewModelStoreOwner)

Set the ViewModelStoreOwner associated with the given View.

Inherited methods

Public methods

get

public static ViewModelStoreOwner get (View view)

Retrieve the ViewModelStoreOwner associated with the given View. This may be used to retain state associated with this view across configuration changes.

Parameters
view View: View to fetch a ViewModelStoreOwner for

Returns
ViewModelStoreOwner The ViewModelStoreOwner associated with this view and/or some subset of its ancestors

set

public static void set (View view, 
                ViewModelStoreOwner viewModelStoreOwner)

Set the ViewModelStoreOwner associated with the given View. Calls to get(View) from this view or descendants will return viewModelStoreOwner.

This should only be called by constructs such as activities or fragments that manage a view tree and retain state through a ViewModelStoreOwner. Callers should only set a ViewModelStoreOwner that will be stable. The associated ViewModelStore should be cleared if the view tree is removed and is not guaranteed to later become reattached to a window.

Parameters
view View: Root view associated with the viewModelStoreOwner

viewModelStoreOwner ViewModelStoreOwner: ViewModelStoreOwner associated with the given view