展会信息港展会大全

Android乘法计算器
来源:互联网   发布日期:2016-01-14 12:20:59   浏览:2060次  

导读:Calculate.javapublic class Calculate extends Activity { private Button myCalculate=null; private EditText factorone=null; private EditText factortwo=null; private TextView myMulti......

Calculate.java

public class Calculate extends Activity {

private Button myCalculate=null;

private EditText factorone=null;

private EditText factortwo=null;

private TextView myMultiply=null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

factorone = (EditText)findViewById(R.id.factorone);

myMultiply = (TextView)findViewById(R.id.myMultiply);

factortwo = (EditText)findViewById(R.id.factortwo);

myCalculate = (Button)findViewById(R.id.myCalculate);

myMultiply.setText(R.string.multiply);

myCalculate.setText(R.string.calculate);

myCalculate.setOnClickListener(new myCalculateOnClickListener());

}

class myCalculateOnClickListener implements OnClickListener {

@Override

public void onClick(View arg0) {

String factoroneStr = factorone.getText().toString();

String factortwoStr = factortwo.getText().toString();

Intent intent = new Intent();

intent.putExtra("one", factoroneStr);

intent.putExtra("two",factortwoStr);

intent.setClass(Calculate.this, Result.class);

Calculate.this.startActivity(intent);

}

}

}

result.java

public class Result extends Activity {

private TextView myResult;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.result);

myResult = (TextView)findViewById(R.id.myResult);

Intent intent = getIntent();

String factoroneStr = intent.getStringExtra("one");

String factortwoStr = intent.getStringExtra("two");

int factoroneInt = Integer.parseInt(factoroneStr);

int factortwoInt = Integer.parseInt(factortwoStr);

int calresult = factoroneInt * factortwoInt;

myResult.setText(calresult + "");

}

}

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<EditText

android:id="@+id/factorone"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

<TextView

android:id="@+id/myMultiply"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

<EditText

android:id="@+id/factortwo"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

<Button

android:id="@+id/myCalculate"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

</LinearLayout>

result.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:id="@+id/myResult"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

</LinearLayout>

string.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="hello">Hello World, Calculate!</string>

<string name="app_name">Calculate</string>

<string name="multiply">乘以</string>

<string name="calculate">计算</string>

<string name="result">计算结果</string>

</resources>

赞助本站

人工智能实验室

相关热词: 乘法 计算器

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港