Android Learning Note-activity&intent

Source: Internet
Author: User

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/51/46/wKioL1RjGFeTbepJAAEOViC79jE926.jpg "title=" 1.png " alt= "Wkiol1rjgfetbepjaaeovic79je926.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/51/48/wKiom1RjF_7x7LZxAACPDZma5-s442.jpg "title=" 2.png " alt= "Wkiom1rjf_7x7lzxaacpdzma5-s442.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/51/48/wKiom1RjGA-TzPJ3AAFblpDx5lY001.jpg "title=" 3.png " alt= "Wkiom1rjga-tzpj3aafblpdx5ly001.jpg"/>

Interface Activity_main.xml

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"      xmlns:tools= "Http://schemas.android.com/tools"     android:layout_width= "Match_parent"     android:layout_height= "Match_parent"     android:paddingbottom= "@ Dimen/activity_vertical_margin "    android:paddingleft=" @dimen/activity_horizontal_margin "     android:paddingright= "@dimen/activity_horizontal_margin"      android:paddingtop= "@dimen/activity_vertical_margin"     tools:context= " Com.example.activity02.MainActivity " >    <!--          <textview        android:layout_width= "Wrap _content "        android:layout_height=" Wrap_content "         android:text= "@strIng/hello_world " />    -->    <EditText         android:id= "@+id/usernameedittext"          android:layout_width= "Fill_parent"         android:layout_ height= "wrap_content"          android:hint= "username"/>     <button        android:id= "@+id/myButton"          android:layout_width= "Fill_parent"          android:layout_height= "Wrap_content"           android:layout_below= "@+id/usernameedittext"/>        <button         android:id= "@+id/sendbutton"          android:layout_widTh= "Fill_parent"         android:layout_height= "Wrap_content"           android:layout_below= "@+id/mybutton"/></RelativeLayout >

Interface Otheractivity.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <textview android:id= "@+id/mytextview" android:layout_width= "Fill_parent" Android:layo ut_height= "Wrap_content"/></linearlayout>


mainactivity.java

public class mainactivity extends actionbaractivity {private button  mybutton;private button sendbutton;private edittext usernameedittext;      @Override     protected void oncreate (bundle savedinstancestate)   {        super.oncreate (savedinstancestate);         setcontentview (R.layout.activity_main);                 myButton =  (Button)  findviewbyid ( R.id.mybutton);         mybutton.settext ("Pass value");                 sendButton =  (Button)   Findviewbyid (R.id.sendbutton);         sendbutton.settext ("Texting");                 usernameEditText =  (EditText)   Findviewbyid (R.id.usernameedittext);                 mybutton.setonclicklistener (New onclicklistener ()  {@Overridepublic  void  onclick (view v)  {//intent intent = new intent (MainActivity.this,  Otheractivity.class); intent intent = new intent (); Intent.setclass (MainActivity.this,  Otheractivity.class); String username = usernameedittext.gettext (). toString (); Intent.putextra ("username",  username); MainActivity.this.startActivity (intent);//startactivity (intent);});                  Sendbutton.setonclicklistener (New onclicklistener ()  {@Overridepublic  void onclick (View &NBSP;V)  {//Call the program Uri uri = uri.parse ("s) of the originating lettermsto:18513430780 "); Intent intent = new intent (Intent.action_sendto, uri); Intent.putextra ("Sms_body",  "The sms text"); StartActivity (intent);}});     }}


Otheractivity.java

public class Otheractivity extends Activity{private TextView mytextview; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Toast.maketext (Getapplicationcontext (), "click", Toast.length_short). Show (); Setcontentview ( r.layout.otheractivity); Mytextview = (TextView) Findviewbyid (R.id.mytextview); String username = getintent (). Getstringextra ("username"); Mytextview.settext ("The value passed is:" + username);}}





This article is from "Avatar" blog, please make sure to keep this source http://shamrock.blog.51cto.com/2079212/1575773

Android Learning Note-activity&intent

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.