Android View data cache

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.