android 使用intent传递参数实现乘法计算
主界面上是两个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传递参数实现乘法计算的更多相关文章
- Android 通过 Intent 传递类对象或list对象
(转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...
- Android 通过 Intent 传递类对象
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...
- android通过 Intent 传递类对象
Android中Intent传递类对象提供了两种方式一种是 通过实现Serializable接口传递对象,一种是通过实现Parcelable接口传递对象. 要求被传递的对象必须实现上述2种接口中的一种 ...
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
今天要给大家讲一下Android中 Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是 Bundle.putP ...
- [转]Android中Intent传递对象的两种方法(Serializable,Parcelable)
http://blog.csdn.net/xyz_lmn/article/details/5908355 今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种 ...
- Android高手进阶教程(十七)之---Android中Intent传递对象的两种方法(Serializable,Parcelable)!
[转][原文] 大家好,好久不见,今天要给大家讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object); ...
- Android中Intent传递类对象的方法一(Serializable)
Activity之间通过Intent传递值,支持基本数据类型和String对象及它们的数组对象byte.byte[].char.char[].boolean.boolean[].short.short ...
- Android——通过Intent传递一些二进制数据的方法有哪些
1.方法 (1)使用Serializable接口实现序列化.利用Bundle.putSerializable(Key, Object);这里objec对象需要实现serializable接口. (2) ...
- android#使用Intent传递对象
参考自<第一行代码>——郭霖 Intent的用法相信你已经比较熟悉了,我们可以借助它来启动活动.发送广播.启动服务等.在进行上述操作的时候,我们还可以在Intent中添加一些附加数据,以达 ...
随机推荐
- 将选择的图片显示在listview中,并显示filename,path和type
if (openFileDialog1.ShowDialog() == DialogResult.OK) { listView1.Items.Clear(); string[] files = ope ...
- jquery的插件机制
jQuery的内核; (function( window, undefined ) { //这就是jQuery的原型 var jQuery = function( selector, context ...
- css reset浅谈
我们都知道,web开发中浏览器兼容性是困扰很多开发者的一个问题.所谓兼容性问题,即不同浏览器对同一段代码有不同的解析效果.而我们的需求往往是无论用户使用何种浏览器查看我们的网站,都应该获得相同或相近的 ...
- 织梦DedeCMS网站地图模板
亲和百度蜘蛛,分页多层次特色,织梦系统最好用的网站地图! 用 DedeCMS(织梦) 系统搭建的网站多数都是以优化为主要目标的网站类型,既然是优化站 SEO 手段就离不开为网站设置网站地图.可是 De ...
- 服务端生成word并压缩打包下载
所需工具 phpwrod 库 php_zip 扩展 下载phpword库,放到类加载路径. 安装php_zip扩展 下载地址 http://pecl.php.net/package/zip linux ...
- 有两个数组a,b,大小都为n;通过交换a,b中的元素,使sum(a)-sum(b)最小。
今天在浏览网页的时候,发现了一个叫做 华为面试题(8分钟写出代码) 的链接,不确定真实性,纯属好奇,就点进去看看 这个可能是很老的题目吧,因为我看到这题目时,底下有好多评论了.提到XX排序,内存占用 ...
- JNI/NDK开发指南(开山篇)
转载请注明出处:http://blog.csdn.net/xyang81/article/details/41759643 相信很多做过Java或Android开发的朋友经常会接触到JNI方面的技术, ...
- Android 基础知识点(持续更新)
一.AndroidManifest 每一个安卓工程都有AndroidManifest.xml的配置文件,在所有项目中该名称都不会变.该文件是Android工程的一个全局配置文件,所有在Android中 ...
- Android 给ListView设置Adapter
Adapter: class MyAdapter extends BaseAdapter { private List<Person> personList; public MyAdapt ...
- 【网络流24题】No.1 搭配飞行员(飞行员配对方案问题)
[问题描述] 飞行大队有若干个来自各地的驾驶员,专门驾驶一种型号的飞机,这种飞机每架有两个驾驶员,需一个正驾驶员和一个副驾驶员.由于种种原因,例如相互配合的问题,有些驾驶员不能在同一架飞机上飞 ...