Android Learning note-edittext&textview&button& menu bar

Source: Internet
Author: User

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/51/5A/wKiom1RjO_PwjxwTAAGPEtBxRo0993.jpg "title=" Qq20141112185214.png "alt=" Wkiom1rjo_pwjxwtaagpetbxro0993.jpg "/>

Interface file 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.activity_03.MainActivity " >    <EditText         android:id= "@+id/factor_one"         android: Layout_width= "Fill_parent"         android:layout_height= "Wrap_content"  />    <textview&nbsP;       android:id= "@+id/symbol"          android:layout_width= "Fill_parent"         android:layout_height= "Wrap_content"         android:layout_below= "@+id/factor_one"  / >    <edittext        android:id= "@+id/ Factor_two "        android:layout_width=" Fill_parent "         android:layout_height= "Wrap_content"          android:layout_below= "@+id/symbol"  />    <Button         android:id= "@+id/multiply"          Android:layout_width= "Fill_parent"         android:layout_height= "Wrap_ Content "        android:layout_below= "@+id/factor_two"  /></RelativeLayout> 

Interface file Result.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/result" android:layout_width= "fill_parent" android:layout_height= "Wrap_con Tent "/></linearlayout>

Mainactivity.java

public class mainactivity extends actionbaractivity {private edittext  factor_one;private edittext factor_two;private textview symbol;private button  multiply;     @Override     protected void oncreate (Bundle  savedinstancestate)  {        super.oncreate ( Savedinstancestate);         setcontentview (R.layout.activity_main);                 factor_one  =  (EditText)  findviewbyid (r.id.factor_one);         factor_two =  (EditText)  findviewbyid (r.id.factor_two);         symbol =  (TextView)  findviewbyid (R.id.symbol);         multiply =  (Button) &NBSP;FINDVIewbyid (r.id.multiply);                 symbol.settext (R.string.symbol);         multiply.settext (" Calculation ");                 Multiply.setonclicklistener (New onclicklistener ()  {@Overridepublic  void onclick (View  V)  {// todo auto-generated method stubstring factor_one_str = factor_ One.gettext (). toString (); String factor_two_str = factor_two.gettext (). toString (); intent intent = new  intent (); Intent.putextra ("Factor_one_str",  factor_one_str); Intent.putextra ("Factor_two_str",  FACTOR_TWO_STR); Intent.setclass (Mainactivity.this, resultactivity.class); MainActivity.this.startActivity (intent);}});     }     @Override     public boolean&Nbsp;oncreateoptionsmenu (menu menu)  {//settings menu     //MenuItem  Android.view.Menu.add (Int groupid, int itemid, int order, int titleres)     menu.add (0, 1, 1, r.string.about);     menu.add (0,  2, 2, r.string.exit);        return  Super.oncreateoptionsmenu (menu);     }        @ Override    public boolean onoptionsitemselected (MenuItem item)  {// Action after selecting the menu option     if  (Item.getitemid ()  == 1)  {//about}else if  ( Item.getitemid ()  == 2)  {//exit finish ();     return super.onoptionsitemselected (item);     }}


Resultactivity.java

public class Resultactivity extends activity{private TextView result; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.result); String factor_one_str = Getintent (). Getstringextra ("Factor_one_str"); String factor_two_str = Getintent (). Getstringextra ("Factor_two_str"); int factor_one = Integer.parseint (factor_one_ STR); int factor_two = Integer.parseint (factor_two_str); result = (TextView) Findviewbyid (R.id.result); Result.settext ( Factor_one * factor_two + "");}}

Strings.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >activity_03</string > <string name= "hello_world" >hello world!</string> <string name= "Action_settings" >Settings< /string> <string name= "symbol" > Multiply </string><string name= "Exit" > Exit </string><string Name= "About" > About </string></resources>

Register activity in Androidmanifest.xml

<activity android:name= ". Resultactivity "android:label=" resultactivity "/>


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

Android Learning note-edittext&textview&button& menu bar

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.