Intent of Android notes passing custom objects

Source: Internet
Author: User

1.

Importjava.util.List;ImportAndroid.os.Parcel;Importandroid.os.Parcelable;/*** 1) Writetoparcel method. This method writes the data of the class to an externally supplied parcel. * 2) Describecontents method. return directly to 0. * 3) Static parcelable.creator<t> interface, this interface has two methods: * Createfromparcel (Parcel in) implements the function of creating an instance of the class from in. * NewArray (int size) creates an array of type T, length of size, returnnew t[size]; This method is used by the outer class to deserialize the array of this class. *  * @authorJL*/ Public classViewPointImplementsparcelable {PrivateString V_name; PrivateList<string>v_picture; PrivateList<string>v_description; /*** The sequence of read in this step should be consistent with the order of Writetoparcel *@paramParcel*/    PrivateViewPoint (Parcel Parcel) {//TODO auto-generated Constructor stubV_name=parcel.readstring (); V_description=parcel.readarraylist (List.class. getClassLoader ()); V_picture=parcel.readarraylist (List.class. getClassLoader ()); //list<string>:p arcel.readarraylist (List.class.getClassLoader ())//map<string, string>:p arcel.readhashmap (Map.class.getClassLoader ())//list<school>:p arcel.readarraylist (School.class.getClassLoader ())//School:(School) parcel.readparcelable (School.class.getClassLoader ())    }     PublicViewPoint () {//TODO auto-generated Constructor stub    }     Public Static FinalParcelable.creator<viewpoint> creator=NewParcelable.creator<viewpoint>() {@Override PublicViewPoint Createfromparcel (Parcel source) {//TODO auto-generated Method Stub            return NewViewPoint (source); } @Override PublicViewpoint[] NewArray (intsize) {            //TODO auto-generated Method Stub            return NewViewpoint[size];        }    };  PublicString Getv_name () {returnV_name; }     Public voidsetv_name (String v_name) { This. V_name =V_name; }     PublicList<string>getv_picture () {returnv_picture; }     Public voidSetv_picture (list<string>v_picture) {         This. V_picture =v_picture; }     PublicList<string>getv_description () {returnv_description; }     Public voidSetv_description (list<string>v_description) {         This. v_description =v_description; } @Override Public intdescribecontents () {//TODO auto-generated Method Stub        return0; } @Override Public voidWritetoparcel (Parcel dest,intflags) {        //TODO auto-generated Method Stub//writes the data to be serialized to the parcel object//list is written: Writelist//school:writeparcelable (Schoolinfo, arg1), and School itself is a Parcelable objectdest.writestring (v_name);        Dest.writelist (v_description);    Dest.writelist (v_picture); }}

Done

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.