The cache of view data is often needed in Android, such as when we want EditText to be cut to another interface, the data entered remains the same.
Reference code:
/*Cache TextView*/ Public classCpcomplexdatepickerextendsFramelayout {PrivateContext Mcontext; /*** Date Display*/ PrivateTextView Mexpiretxt; /*** The selected date*/ PrivateString mselecteddate; /*** Layout*/ PrivateView Mcontentview; PublicCpcomplexdatepicker (Context context) {Super(context); Mcontext=context; Init (); } PublicCpcomplexdatepicker (Context context, AttributeSet attrs) {Super(context, attrs); Mcontext=context; Init (); } /*** Set Date * *@paramtext*/ Public voidSetText (String text) {if(Mexpiretxt! =NULL) {mexpiretxt.settext (text); }} @SuppressLint ("Inflateparams") Private voidinit () {Mcontentview=Layoutinflater.from (Mcontext). Inflate (R.layout.realname_complex_date_picker, (Viewgrou p) Getrootview ()); Mexpiretxt=(TextView) mcontentview. Findviewbyid (R.id.pid_card_expire_txt); } /*** Save*/@Override Publicparcelable onsaveinstancestate () {parcelable parcelable=Super. Onsaveinstancestate (); savedstate SS=Newsavedstate (parcelable); Ss.mcachedate=mselecteddate; returnSS; } /*** Recovery*/@Override Public voidonrestoreinstancestate (parcelable State) {savedstate SS=(savedstate) state; Mselecteddate=ss.mcachedate; //Recover Text contentSetText (ss.mcachedate); Super. Onrestoreinstancestate (Ss.getsuperstate ()); } /*** Data Recovery * *@authorWangmingxian **/ Public Static classSavedstateextendsBasesavedstate {/*** Cache Date*/String mcachedate; Savedstate (parcelable superstate) {Super(superstate); } @Override Public voidWritetoparcel (Parcel out,intflags) { Super. Writetoparcel (out, flags); Out.writestring (mcachedate); } Privatesavedstate (Parcel in) {Super(in); Mcachedate=in.readstring (); } Public Static FinalParcelable.creator<savedstate> Creator =NewParcelable.creator<savedstate>() { Publicsavedstate Createfromparcel (Parcel in) {return Newsavedstate (in); } PublicSavedstate[] NewArray (intsize) { return NewSavedstate[size]; } }; }}
Android View data cache