主界面上是两个EditText和一个按钮。用于输入两个数字参数。

calcute.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
> <EditText
android:id="@+id/factory1"
android:layout_height="wrap_content"
android:layout_width="100dip"
/>
<TextView
android:layout_width="50dip"
android:layout_height="wrap_content"
android:text="X"
android:layout_marginLeft="30dip"
/>
<EditText
android:id="@+id/factory2"
android:layout_height="wrap_content"
android:layout_width="100dip"
/>
</LinearLayout>
<Button
android:id="@+id/calute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算"
/> </LinearLayout>

处理calcute的java程序

CaluteMain.java:

package com.example.wenandroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; public class CaluteMain extends Activity {
private EditText factory1;
private EditText factory2;
private Button calute;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.calcute);
factory1=(EditText)findViewById(R.id.factory1);
factory2=(EditText)findViewById(R.id.factory2);
calute=(Button)findViewById(R.id.calute);
calute.setOnClickListener(new MyOnClickListener());
}
class MyOnClickListener implements OnClickListener{ @Override
public void onClick(View v) {
String factoryStr1=factory1.getText().toString();
String factoryStr2=factory2.getText().toString();
Intent intent=new Intent(CaluteMain.this,CaluteResult.class);
intent.putExtra("one", factoryStr1);
intent.putExtra("two", factoryStr2);
startActivity(intent);
} }
}

计算结果的界面:caluteresult.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

接收两个数字参数并显示结果的Activity。CaluteResult.java:

package com.example.wenandroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView; public class CaluteResult extends Activity {
private TextView resultView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.caluteresult);
resultView=(TextView)findViewById(R.id.result);
Intent intent=getIntent();
String factoryStr1=intent.getStringExtra("one");
String factoryStr2=intent.getStringExtra("two");
//将字符串转换为整形
int factoryInt1=Integer.parseInt(factoryStr1);
int factoryInt2=Integer.parseInt(factoryStr2);
int result=factoryInt1*factoryInt2;
resultView.setText("结果是:"+result+""); } }

android 使用intent传递参数实现乘法计算的更多相关文章

  1. Android 通过 Intent 传递类对象或list对象

    (转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...

  2. Android 通过 Intent 传递类对象

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...

  3. android通过 Intent 传递类对象

    Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...

  4. Android中Intent传递对象的两种方法(Serializable,Parcelable)

    今天要给大家讲一下Android中 Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是 Bundle.putP ...

  5. [转]Android中Intent传递对象的两种方法(Serializable,Parcelable)

    http://blog.csdn.net/xyz_lmn/article/details/5908355 今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种 ...

  6. Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!

    [转][原文] 大家好,好久不见,今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object); ...

  7. Android中Intent传递类对象的方法一(Serializable)

    Activity之间通过Intent传递值,支持基本数据类型和String对象及它们的数组对象byte.byte[].char.char[].boolean.boolean[].short.short ...

  8. Android——通过Intent传递一些二进制数据的方法有哪些

    1.方法 (1)使用Serializable接口实现序列化.利用Bundle.putSerializable(Key, Object);这里objec对象需要实现serializable接口. (2) ...

  9. android#使用Intent传递对象

    参考自<第一行代码>——郭霖 Intent的用法相信你已经比较熟悉了,我们可以借助它来启动活动.发送广播.启动服务等.在进行上述操作的时候,我们还可以在Intent中添加一些附加数据,以达 ...

随机推荐

  1. WordPress标题函数wp_title()详解

    在wp_title()中通常是在页面头部的title元素中.当wp_title()在主页主循环(loop)外时,可以用在模板的任何地方. 用法: <?php wp_title( $sep, $e ...

  2. 7 -- Spring的基本用法 -- 8...

    7.8 深入理解容器中的Bean 7.8.1 抽象Bean与子Bean 把多个<bean.../>配置中相同的信息提取出来,集中成配置模版------这个配置模版并不是真正的Bean,因此 ...

  3. UM分享 - 详解

    官网: http://dev.umeng.com 友盟现在发展的很壮大! 有熟为人知的社会化分享\统计分析\消息推送\即时通信\自动更新\多媒体服务等功能, 今天就其中第一项 分享功能, 做出分解. ...

  4. LightOj_1408 Batting Practice

    题目链接 题意: 击球训练中, 你击中一个球的概率为p,连续击中k1个球, 或者连续击空k2个球, 则训练结束. 求结束训练所击球次数的期望. 思路: 设f[x]为连续击中x个球, 距离结束训练所需要 ...

  5. bootstrap table 服务器端分页例子分享

    这篇文章主要介绍了bootstrap table 服务器端分页例子分享,需要的朋友可以参考下 1,前台引入所需的js 可以从官网上下载 复制代码代码如下: function getTab(){var ...

  6. BZOJ 1754: [Usaco2005 qua]Bull Math

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  7. 【技术帖】解决 Hudson jenkins 连接等待中 - Waiting for next av

    今天构建项目发现如下问题: jenkins 连接等待中 - Waiting for next available executor 左下角那块一直不运行构建,一直在连接等待. 于是,进入一级页面, 右 ...

  8. 四校训练 warm up 14

    A:Pythagoras's Revenge 代码: #include<cstdio> #define ll long long using namespace std; int main ...

  9. 关于entity framework

    http://www.cnblogs.com/lsxqw2004/archive/2009/05/31/1495240.html http://www.open-open.com/lib/view/o ...

  10. MinGW中的头文件路径级环境变量设置

    整理自 MinGW中的头文件路径   C头文件目录%MINGW_PATH%/include下有头文件,里面有strcpy等c函数的声明. C++头文件目录%MINGW_PATH%/lib/gcc/mi ...