android - databinding trigger only in onCreateView -


i starting fragment android studio when mobile's screen off.

the fragment attached activity, custom bind adapter trigger once in oncreateview.

layout:

<layout          ...     <data>          <variable             name="viewmodel"             ...      </data>      ...         android:layout_width="match_parent"         android:layout_height="match_parent"         scanner:state="@{viewmodel.state}"         />  </layout> 

my observable:

public class stateresumepause extends baseobservable {      public enum state {         initial, pause, resume, resumeafterscan     }      private state state = state.initial;      public void setstate(state state) {         this.state = state;         notifypropertychanged(br.state);     }      @bindable     public state getstate() {         return state;     } } 

fragment:

public class oscannerfragment extends fragment {      public static oscannerfragment newinstance() {         return new oscannerfragment();     }      private oscannerviewmodel viewmodel = new oscannerviewmodel();       @nullable     @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {          scannerfragmentbinding binding = databindingutil.inflate(inflater, r.layout.scanner_fragment, container, false);         binding.setviewmodel(this.viewmodel);          return binding.getroot();     }      @override     public void onresume() {         super.onresume();          this.viewmodel.onresume();     }      @override     public void onpause() {         super.onpause();          this.viewmodel.onpause();     } } 

and viewmodel binding in fragment.

public class oscannerviewmodel extends viewmodel {      public final observablefield<stateresumepause> state = new observablefield<>(new stateresumepause(this));      public void onresume() {         this.state.get().setstate(stateresumepause.state.resume);     }      public void onpause() {         this.state.get().setstate(stateresumepause.state.pause);     }  } 

methods fragmet, viewmodel , observable triggered when fragment resume or pause.

but, 1 trigger in custom binding adapter.

here:

@bindingadapter("scanner:state")     public static void state(zbarscannerview view, stateresumepause state) {           switch (state.getstate()) {             ...         }      } 

and finally: works when use debug mode in android studio (on launch appliacation).

any idea, suggestion?


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -