Activity gets the return value

Source: Internet
Author: User

 Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);            Setcontentview (R.layout.activity_main); }     Public voidClick (View c) {//jump to select contact ActivityIntent Intent =NewIntent ( This, Contactactivity.class);//startactivity (Intent); //The activity initiated with this API will be onactivityresult when it is destroyed.Startactivityforresult (Intent, 10); }            //If an activity returns data when it is destroyed, this method is called to receive the data//Requestcode: Used to differentiate which activity the data came from//ResultCode: Used to differentiate what type of data is returned@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        //TODO auto-generated Method Stub        Super. Onactivityresult (Requestcode, ResultCode, data); String name= Data.getstringextra ("name"); if(Requestcode = = 10) {EditText et=(EditText) Findviewbyid (r.id.et);        Et.settext (name); }            }    }
 Public classContactactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub        Super. OnCreate (savedinstancestate);                Setcontentview (r.layout.activity_contact); ListView LV=(ListView) Findviewbyid (r.id.lv); FinalString[] Objects =Newstring[]{"Very small",                "Brother forced",                "World class XXX",                "National Service First"        }; Lv.setadapter (NewArrayadapter<string> ( This, R.layout.item_listview, R.id.tv, objects)); //Click to listen to the ListView settings entryLv.setonitemclicklistener (NewOnitemclicklistener () {//when an entry is clicked, this method calls@Override Public voidOnitemclick (adapterview<?>Parent, view view,intPositionLongID) {//when the activity returns, the data is passed through the intent objectIntent data =NewIntent (); //encapsulates the data to be passed into the intent objectData.putextra ("name", objects[position]); //when the current activity is destroyed, the intent of data is passed to the activity that initiates the current activity.Setresult (1, data); //Destroy Current Activityfinish ();    }        }); } @Override Public voidonbackpressed () {//TODO auto-generated Method Stub        Super. onbackpressed (); }}

Activity gets the return value

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.