---
title: "Android实现计算器功能"
author: "fgh2011"
date: "2011-03-06T01:32:00Z"
tags: []
slug: "android"
draft: false
lastmod: "2015-01-22T23:45:06Z"
id: 2178732
url: "https://fgh2011.iteye.com/blog/2178732"
---

创建两个Activity Calculate.java 和 Result.java

Calculate.java 用于显示计算的页面 Result.java用于显示结果

先在main.xml中写四个控件

main.xml

&lt;?xml version="1.0" encoding="utf-8"?&gt;  
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:orientation="vertical"  
android:layout\_width="fill\_parent"  
android:layout\_height="fill\_parent"&gt;

&lt;EditText  
android:id="@+id/VarOne"  
android:layout\_width="fill\_parent"  
android:layout\_height="wrap\_content"  
/&gt;  
&lt;TextView  
android:id="@+id/symbol"  
android:layout\_width="fill\_parent"  
android:layout\_height="wrap\_content"  
/&gt;  
&lt;EditText  
android:id="@+id/VarTwo"  
android:layout\_width="fill\_parent"  
android:layout\_height="wrap\_content"  
/&gt;  
&lt;Button  
android:id="@+id/calculate"  
android:layout\_width="fill\_parent"  
android:layout\_height="wrap\_content"  
/&gt;  
&lt;/LinearLayout&gt;

代码如下：

Calculate.java

Result.java

新建一个result.xml 为result.java页面编写控件

result.xml

同时修改AndroidManifest.xml文件 在 &lt;application&gt;&lt;/application&gt;标签里面添加以下代码

在strings.xml里设置值

strings.xml

这样一个实现乘法的功能就实现了