Andriod first app-computer

Source: Internet
Author: User

Andriod first app-computer

Andriod first app-computer

Personal information: He is a junior majoring in software engineering at yanda University;

My blog: google searches for "cqs_2012;

My hobbies: I love data structures and algorithms and hope to make my own contribution to algorithm work in the future;

Programming Language: java;

Programming Environment: Windows 7 Professional Edition x64;

Programming tools: jdk, eclipse, AVD;

Drawing tools: office 2010 powerpoint;

Hardware information: 7G-3 Notebook;

What you want to say

I have never touched on andriod development before. I suddenly liked it, but it was not very difficult. Today I wrote a small andriod application called a calculator to implement the computing function.

Self-Program

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

Continue. Click 2.


Then click operations, such as +

At this time, the data box will be automatically cleared, and then wait for the input, click 5

Then click =

Other functions are not displayed.

This program meets the XML file Layout

          
          
                                                                                                                                                                                         


Java activity processing program in the background of this program

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 Button btn2;private Button btn3;private Button btn4;private Button btn5;private Button btn6;private Button btn7;private Button 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 = ' ';private EditText 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;}}}


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.