android 乘法计算器,一个简单的乘法计算器实例,实现的功能是在一个Activity上面显示乘法左边,另一个activity上面显示乘法...

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/factorOne"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

android:id="@+id/symbol"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

android:id="@+id/factorTwo"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

android:id="@+id/calculate"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

ResultActivity中的代码

1.接受从Activity03当中所传递的值

2.计算两个值的积

3.将计算的结果显示在Activity上

public class ResultActivity extends Activity{

private TextView resultView;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.result);

resultView = (TextView)findViewById(R.id.result);

//得到Intent对象当中的值

Intent intent = getIntent();

//通过键值对取值

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

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

//因为是String,不能相乘 ,所以先换算成整型

int factorOneInt = Integer.parseInt(factorOneStr);

int factorTwoInt = Integer.parseInt(factorTwoStr);

//计算两个值的积

int result = factorOneInt * factorTwoInt;

resultView.setText(result + "");

}

}

Layout中相应的result.xml中的配置

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/result"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

/>

Values中String.xml中的配置:配置ID号,方便可以通过ID来引用,方便以后代码的改写

Hello World, Activity03!

activity03

result

乘以

计算

退出

关于

Manifest.xml的配置:主要是配置哪个Activity先启动等一些信息

package="mars.activity03"

android:versionCode="1"

android:versionName="1.0">

android:label="@string/app_name">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package ymq.demo03; import android.app.Activity; import android.os.Bundle; import android.view.*; import android.widget.*; public class demo03 extends Activity { /** Called when the activity is first created. */ String str=""; EditText et; int c=0,flag=0; double b=0.0,g=0.0,f=0.0; View vi; public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0, 1, 1, "退出"); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub if(item.getItemId()==1){finish();} return super.onOptionsItemSelected(item); } //计算方法 public double calculater(){ switch(c){ case 0:f=g;break; case 1:f=b+g;break; case 2:f=b-g;break; case 3:f=b*g;break; case 4:f=b/g;break; } b=f; c=0; return f; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获得按键 final Button number[]=new Button[10]; final Button fuhao[]=new Button[11]; fuhao[0]=(Button)findViewById(R.id.button01); fuhao[1]=(Button)findViewById(R.id.button02); fuhao[2]=(Button)findViewById(R.id.button03); fuhao[3]=(Button)findViewById(R.id.button04); fuhao[4]=(Button)findViewById(R.id.button05); fuhao[5]=(Button)findViewById(R.id.button06); fuhao[6]=(Button)findViewById(R.id.buttonce); fuhao[7]=(Button)findViewById(R.id.buttonc); fuhao[8]=(Button)findViewById(R.id.zheng); fuhao[9]=(Button)findViewById(R.id.kaifang); fuhao[10]=(Button)findViewById(R.id.pingfang); number[0]=(Button)findViewById(R.id.button0); number[1]=(Button)findViewById(R.id.button1); number[2]=(Button)findViewById(R.id.button2); number[3]=(Button)findViewById(R.id.button3); number[4]=(Button)findViewById(R.id.button4); number[5]=(Button)findViewById(R.id.button5); number[6]=(Button)findViewById(R.id.button6); number[7]=(Butto

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值