i have seen databindingcomponent in official api doc.
https://developer.android.com/reference/android/databinding/databindingutil.html
this interface generated during compilation contain getters used instance bindingadapters. when bindingadapter instance method, instance of class implementing method must instantiated. interface generated getter each class name get* * simple class name of declaring bindingadapter class/interface. name collisions resolved adding numeric suffix getter.
an instance of class may passed static or instance bindingadapters first parameter.
if using dagger 2, developer should extend interface , annotate extended interface component.
however, cannot find example usage of class in web. can know , how use it.
i tried make simple code , debug see what's showed null variable on a
variable.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); activitymainbinding binding= databindingutil.setcontentview(this,r.layout.activity_main); android.databinding.databindingcomponent = databindingutil.getdefaultcomponent(); setcontentview(binding.getroot()); }
from documentation know
this interface generated during compilation contain getters used instance bindingadapters. when bindingadapter instance method, instance of class implementing method must instantiated. interface generated getter each class name get* * simple class name of declaring bindingadapter class/interface. name collisions resolved adding numeric suffix getter.
an instance of class may passed static or instance bindingadapters first parameter.
if using dagger 2, developer should extend interface , annotate extended interface component.
this tells interface used , generated injecting factory instances implementing custom @bindingadapter
methods. can configure data bindings different situations or layouts or supply more general state. if have @ default databindingcomponent
class in android studio find located in build/generated/source/apt/dev.
the methods can use databindingcomponent
are
considering define interface like
public interface foo { @bindingadapter("foobar") void foobar(view view, string baz); }
an android.databinding.databindingcomponent
interface gets generated
public interface databindingcomponent { di.pkg.foo getfoo(); }
this @bindingadapter
host gets used in data bindings, need implement interface , use 1 of methods given above like
databindingutil.setdefaultcomponent(new databindingcomponent(){ @override public foo getfoo() { return new foo() { @override public void foobar(view view, string baz) { if (view instanceof textview) ((textview) view).settext(baz); } }; } });
in example null databindingutil.getdefaultcomponent()
because you've never set default component yourself.
Comments
Post a Comment