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中添加一些附加数据,以达 ...
随机推荐
- jquery api 笔记(2) 事件 事件对象
事件 #1.resize() 缩放窗体:window.resizeTo(width, height); 并不是兼容做法. #2 .scroll() ->获取滚动条的位置: .scro ...
- Html代码Font-Size中px与pt的区别
一个是设备坐标,一个是逻辑坐标,两者是不同的. px是个相对单位,一般像素的参考值为:在一个像素密度是90 pdi的显示器上,正常人从距离显示器28英寸处看一个像素的视角应该不小于0.0227度. 1 ...
- 在redis中查询一个KEY的值
写入某个key: set MPM_YYC_XTJ_0 "abcde" [set key value]
- OC中格式化输出符号
定义 说明 %@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, ...
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
目录[-] 1.添加设置项 2.设置的控件 3.编辑设置项的文件 4.在程序中获取Settings 和写入Settings 添加UI 5.实现读取设置和保存代码 在Android手机上, 在某个程序里 ...
- SQL Server强制删除复制发布
原文地址:http://blog.csdn.net/leamonjxl/article/details/7352208 SQL Server 中 存在以前(系统还原前)的发布内容,使用鼠标->右 ...
- python面向对象高级编程
正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: >>> class Studen ...
- 两种方法,获取磁盘剩余空间--PYTHON
import ctypes import os import platform import sys def get_free_space_mb(folder): """ ...
- logstash 贪婪匹配
05:50:47 192.168.5.116 GET /Hotel/HotelDisplay/cncqcqb230 - 80 - 192.168.9.2 Mozilla/5.0+(Macintosh; ...
- linux解压cpio.gz类型文件
1. gunzip XXX.cpio.gz –> 得到 XXX.cpio 文件 2. cpio -idmv <XXX.cpio –> 得到 XXX 文件夹