Andriod First App-computer

Source: Internet
Author: User

Andriod First App-computer

Personal information: studied at Yan University undergraduate software engineering major at present;

I blog: Google search "cqs_2012" can be;

Personal Hobbies: Love data structure and algorithms, hope to work in the future algorithm to make their own contribution to the people;

Programming language: Java;

Programming Bad Environment: Windows 7 Professional Edition x64;

Programming Tools: JDK,ECLIPSE,AVD;

Cartographic tools: Office in PowerPoint;

Hardware information: 7g-3 notebook;

What you want to say.

Previously did not contact the andriod development, the sudden contact feeling very like, the difficulty is not very big, today wrote a andriod small application, called the calculator, realize the calculation function.

Own program

At the beginning, the input box is 0, click 1 to wait for input

Continue, click 2


Then click Actions, such as +

When the data frame is automatically zeroed, and then waits for input, click 5

Then click =

Other features are no longer displayed.

This program meets the layout XML file

<?xml version= "1.0" encoding= "Utf-8"? ><absolutelayout xmlns:android= "http://schemas.android.com/apk/res/     Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " android:background= "#000" > <edittext android:id= "@+id/computerfirstedt" Android:lay Out_width= "Fill_parent" android:layout_height= "50DP" android:layout_x= "0DP" android:layou T_y= "0DP" android:ems= "> </EditText> <button android:id=" @+id/btnnumbe R1 "android:layout_width=" 50DP "android:layout_height=" wrap_content "android:layout_x=" 0DP "Android: Layout_y= "50DP" android:text= "1"/> <button android:id= "@+id/btnnumber2" and            Roid:layout_width= "50DP" android:layout_height= "wrap_content" android:layout_x= "60DP" android:layout_y= "50DP" android:text= "2"/>       <button android:id= "@+id/btnnumber3" android:layout_width= "50DP" android:layout        _height= "Wrap_content" android:layout_x= "120DP" android:layout_y= "50DP" android:text= "3"/> <button android:id= "@+id/btnnumber4" android:layout_width= "50DP" Android:layout_hei                     ght= "Wrap_content" android:layout_x= "180DP" android:layout_y= "50DP" android:text= "4"/> <button android:id= "@+id/btnnumber5" android:layout_width= "50DP" android:l        ayout_height= "Wrap_content" android:layout_x= "0DP" android:layout_y= "110DP" android:text= "5"/> <button android:id= "@+id/btnnumber6" android:layout_width= "50DP" android:layout        _height= "Wrap_content" android:layout_x= "60DP" android:layout_y= "110DP" android:text= "6"/>           <button Android:id= "@+id/btnnumber7" android:layout_width= "50DP" android:layout_height= "Wrap_content"            android:layout_x= "120DP" android:layout_y= "110DP" android:text= "7"/> <button             Android:id= "@+id/btnnumber8" android:layout_width= "50DP" android:layout_height= "Wrap_content"            android:layout_x= "180DP" android:layout_y= "110DP" android:text= "8"/> <button             Android:id= "@+id/btnnumber9" android:layout_width= "50DP" android:layout_height= "Wrap_content" android:layout_x= "0DP" android:layout_y= "170DP" android:text= "9"/> <button an             Droid:id= "@+id/btnnumber0" android:layout_width= "50DP" android:layout_height= "Wrap_content" android:layout_x= "60DP" android:layout_y= "170DP" android:text= "0"/> <button an Droid:id= "@+id/btnnumberC "android:layout_width=" 50DP "android:layout_height=" Wrap_content "android:layout_x=" 120DP "android:layout_y=" 170DP "android:text=" Empty "/> <button android:id=" @+id/btnnum BerR "android:layout_width=" 50DP "android:layout_height=" Wrap_content "android:layout_x= "180DP" android:layout_y= "170DP" android:text= "="/> <button android:id= "@ +id/btnnumberm "android:layout_width=" 50DP "android:layout_height=" Wrap_content "Android : layout_x= "0DP" android:layout_y= "230DP" android:text= "*"/> <button android:id= "@+i D/btnnumbera "android:layout_width=" 50DP "android:layout_height=" Wrap_content "android:l ayout_x= "60DP" android:layout_y= "230DP" android:text= "+"/> <button android:id= "@+i           D/btnnumbers " Android:layout_width= "50DP" android:layout_height= "wrap_content" android:layout_x= "120DP" Androi            D:layout_y= "230DP" android:text= "-"/> <button android:id= "@+id/btnnumberd" Android:layout_width= "50DP" android:layout_height= "wrap_content" android:layout_x= "180DP" Androi D:layout_y= "230DP" android:text= "/"/> </AbsoluteLayout>


This program background Java activity handler

Import Com.icss.myhello.r.array;import android.app.activity;import Android.content.intent;import android.os.Bundle ; Import Android.text.textutils;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;import android.widget.Toast; public class Firstactivity extends Activity implements onclicklistener{private button Btn0;private button btn1;private Bu Tton btn2;private button btn3;private button btn4;private button btn5;private button btn6;private button btn7;private Butt  On btn8;private button btn9;private button btnm;private button btnd;private button btna;private button btns;private button Btnr;private Button btnc;private Integer number1 = 0;private integer number2 = 0;private char operation = ';p rivate Edi Ttext result; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview (r.layout.firstactivity);Btn0 = (Button) Findviewbyid (R.ID.BTNNUMBER0), btn1 = (button) Findviewbyid (r.id.btnnumber1); btn2 = (Button) Findviewbyid (r.id.btnnumber2); btn3 = (Button) Findviewbyid (r.id.btnnumber3); btn4 = (Button) Findviewbyid ( R.ID.BTNNUMBER4) Btn5 = (Button) Findviewbyid (R.ID.BTNNUMBER5); btn6 = (Button) Findviewbyid (R.ID.BTNNUMBER6); btn7 = ( button) Findviewbyid (r.id.btnnumber7), Btn8 = (button) Findviewbyid (r.id.btnnumber8); btn9 = (Button) Findviewbyid ( R.ID.BTNNUMBER9) Btna = (Button) Findviewbyid (r.id.btnnumbera); btns = (Button) Findviewbyid (r.id.btnnumbers); BtnM = ( button) Findviewbyid (r.id.btnnumberm), btnd = (button) Findviewbyid (r.id.btnnumberd); Btnr = (Button) Findviewbyid ( R.ID.BTNNUMBERR); BTNC = (Button) Findviewbyid (R.ID.BTNNUMBERC); result = (EditText) Findviewbyid ( R.id.computerfirstedt); Btn0.setonclicklistener (this), Btn1.setonclicklistener (this); Btn2.setonclicklistener ( This), Btn3.setonclicklistener (This), Btn4.setonclicklistener (This), Btn5.setonclicklistener (this); Btn6.setonclicklistener (This); Btn7.setonclicklistener (this), Btn8.setonclicklistener (This), Btn9.setonclicklistener (this); Btna.setonclicklistener (This), Btnd.setonclicklistener (This), Btns.setonclicklistener (this); Btnm.setonclicklistener (This), Btnr.setonclicklistener (This), Btnc.setonclicklistener (this); Result.settext ( Number1.tostring ());} @Overridepublic void OnClick (view view) {//TODO auto-generated method Stubswitch (View.getid ()) {case R.ID.BTNNUMBER0: Number1 = Number1*10;result.settext (number1.tostring ()); Break;case r.id.btnnumber1:number1 = number1*10+1; Result.settext (Number1.tostring ()); Break;case R.id.btnnumber2:number1 = Number1*10+2;result.settext ( Number1.tostring ()); Break;case r.id.btnnumber3:number1 = Number1*10+3;result.settext (number1.toString ()); break; Case r.id.btnnumber4:number1 = Number1*10+4;result.settext (number1.tostring ()); Break;case R.id.btnnumber5:number1 = Number1*10+5;result.settext (Number1.tostring ()); Break;case R.id.btnnumber6:number1 = Number1*10+6;result.setText ( Number1.tostring ()); Break;casE r.id.btnnumber7:number1 = Number1*10+7;result.settext (number1.tostring ()); Break;case R.id.btnnumber8:number1 = Number1*10+8;result.settext (Number1.tostring ()); Break;case R.id.btnnumber9:number1 = Number1*10+9;result.setText ( Number1.tostring ()); Break;case r.id.btnnumbera:number2 = number1;operation = ' + '; number1 = 0;result.settext ( Number1.tostring ()); Break;case r.id.btnnumbers:number2 = Number1;operation = '-'; number1 = 0;result.settext ( Number1.tostring ()); Break;case r.id.btnnumberm:number2 = number1;operation = ' * '; number1 = 0;result.settext ( Number1.tostring ()); Break;case r.id.btnnumberd:number2 = Number1;operation = '/'; number1 = 0;result.settext ( Number1.tostring ()); Break;case r.id.btnnumberc:number1 = Number2 = 0;result.settext (number1.tostring ()); break;case R.id.btnnumberr:switch (operation) {case ' + ': Number1 = Number1+number2;result.settext (number1.tostring ()); number1 = number2 = 0;break;case '-': Number1 = Number1-number2;result.settext (number1.tostring ()); number1 = Number2 = 0;bReak;case ' * ': Number1 = Number1*number2;result.settext (number1.tostring ()); number1 = Number2 = 0;break;case '/': if ( Number2! = 0) {number1 = Number1/number2;result.settext (number1.tostring ());} else Result.settext ("error input"); number1 = Number2 = 0;break;default:break;} Break;default:break;}}}


Andriod First App-computer

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.