Receive value transfer method between Android Interfaces

Source: Internet
Author: User
Mainactivity. Java Package com. mainactivity;Import Android. App. activity;Import Android. content. intent;Import Android. OS. Bundle;Import Android. View. view;Import Android. widget. Button;Import Android. widget. edittext;Public class mainactivity extends activity {Private button nextbutton;Private edittext nameedit;Private edittext phoneedit;@ OverridePublic void oncreate (bundle icicle ){Super. oncreate (icicle );Setcontentview (R. layout. Main );// Upload all WidgetsLoadwidget ();Nextbutton. setonclicklistener (New button. onclicklistener (){@ OverridePublic void onclick (view ){// Send data to the next actitityDelivertonextactitity ();}});}Public void delivertonextactitity (){// Create a bundle object and put the number of items to be deleted in the bundleBundle bundle = new bundle ();Bundle. putstring ("name", nameedit. gettext (). tostring ());Bundle. putstring ("phone", phoneedit. gettext (). tostring ());Intent intent = new intent ();// Set a actitityIntent. setclass (this, secondactivity. Class );Intent. putextras (bundle );// Open an activityStartactivity (intent );}Private void loadwidget (){Nextbutton = (button) findviewbyid (R. Id. nextbutton );Nameedit = (edittext) findviewbyid (R. Id. nameedit );Phoneedit = (edittext) findviewbyid (R. Id. phoneedit );}}Secondactivity. JavaPackage com. mainactivity;Import Android. App. activity;Import Android. OS. Bundle;Import Android. View. view;Import Android. widget. Button;Import Android. widget. textview;Public class secondactivity extends activity {@ OverridePublic void oncreate (bundle icicle ){Super. oncreate (icicle );Setcontentview (R. layout. Second );Textview content = (textview) findviewbyid (R. Id. content );Button backbutton = (button) findviewbyid (R. Id. backbutton );// Obtain the bundle object generated by the previous activityBundle bundle = getintent (). getextras ();Content. settext ("name:" + bundle. getstring ("name") + "Tel:" + bundle. getstring ("phone "));Backbutton. setonclicklistener (New button. onclicklistener (){@ OverridePublic void onclick (view ){// End the activityFinish ();}});}}Main. xml<? XML version = "1.0" encoding = "UTF-8"?><Absolutelayout xmlns: Android = "http://schemas.android.com/apk/res/android"Android: Orientation = "vertical"Android: layout_width = "fill_parent"Android: layout_height = "fill_parent"Android: Id = "@ + ID/widget149"><Textview Android: Id = "@ + ID/nametext"Android: layout_height = "wrap_content"Android: layout_width = "wrap_content"Android: layout_x = "0px"Android: layout_y = "18px"Android: text = "name:"></Textview><Edittext Android: Id = "@ + ID/nameedit"Android: layout_height = "36px"Android: layout_width = "100px"Android: layout_x = "58px"Android: layout_y = "12px"></Edittext><Textview Android: Id = "@ + ID/phonetext"Android: layout_height = "-12px"Android: layout_width = "wrap_content"Android: layout_x = "-1px"Android: layout_y = "62px"Android: text = "Tel:"></Textview><Edittext Android: Id = "@ + ID/phoneedit"Android: layout_height = "36px"Android: layout_width = "100px"Android: layout_x = "58px"Android: layout_y = "57px"></Edittext><Button Android: Id = "@ + ID/nextbutton"Android: layout_height = "wrap_content"Android: layout_width = "wrap_content"Android: layout_x = "4px"Android: layout_y = "103px"
Related Article

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.