android - ObservableParcelable<String> is not working -
in official documentation see use of observableparcelable
string
this:
public final observableparcelable<string> name = new observableparcelable<string>();
but since string
not implement parcelable
there no possibility of being compiled. how can make object extend baseobservable
, have observable fields , parcelable @ same time?
you can save not parcelable fields, example:
public class viewmodel extends baseobservable implements parcelable { private observablefield<string> title = new observablefield<>(); private observableint count = new observableint(); private viewmodel(parcel parcel) { title.set(parcel.readstring()); count.set(parcel.readint()); } @override public int describecontents() { return 0; } @override public void writetoparcel(parcel parcel, int flags) { parcel.writestring(title.get()); parcel.writeint(count.get()); } public static final creator<viewmodel> creator = new creator<viewmodel>() { @override public viewmodel createfromparcel(parcel in) { return new viewmodel(in); } @override public viewmodel[] newarray(int size) { return new viewmodel[size]; } }; }
but if want work parcelable, should implement interface classes
public class parcelablestring implements parcelable { private string value; /*getter, setter , implementation of parcelable*/ }
Comments
Post a Comment