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中添加一些附加数据,以达 ...
随机推荐
- 如何用angularjs制作一个完整的表格之三__在ng-repeat中使用ng-model
在ng-repeat中使用ng-model时会有许多问,有的人碰到无法获取绑定的数据内容,有的人遇到改动绑定的数据内容时所有循环生成的内容一起改变.上面的问题我在开发时也遇到过,但是解决后我却怎么也还 ...
- 犯这个错误的肯定不止我一个 关于File
File.Create(string filePath)这种用法所有人都知道,这两天用到的时候却发现一个问题. 需要先判断文件是否存在,如果不存在则创建文件,然后向该文件写入数据,后续定时Append ...
- XML1_XML基础
1.XML的作用 XML 被设计用来传输和存储数据.所以XML 是不作为的. 2.简单的描述 XML 文档形成一种树结构. XML 文档必须包含根元素.该元素是所有其他元素的父元素.XML 文档中的元 ...
- bootstrap table 服务器分页
1.封装MODEL using System;using System.Collections.Generic;using System.Linq;using System.Text;using Sy ...
- Word添加新编号
要用到(1)(2),不想手写,但是word只有1.2.3和1)2)3),我就自定义哦.
- Mongodb使用
Mongodb基本的原则是:条件句是内层文档的键,修改器是外层文档的键[即,修改器要修改的字段声明在修改器内部].1.$size,用于查询数组大小为size的记录db.a.find({"co ...
- 【网络流24题】 No.12 软件补丁问题(最小转移代价 最短路)
[题意] T 公司发现其研制的一个软件中有 n 个错误, 随即为该软件发放了一批共 m 个补丁程序. 每一个补丁程序都有其特定的适用环境, 某个补丁只有在软件中包含某些错误而同时又不包含另一些错误时才 ...
- 李洪强iOS开发之-环信02.3_具体接口讲解 - Apple Docs
http://www.easemob.com/apidoc/ios/chat3.0/annotated.html Apple Docs.
- QWidget与HWND的互相转换
QWidget与HWND的互相转换 在编写Windows的应用程序时,我们有时不可避免地要与Windows平台固有的Win32 API打交道,但是Win32 API里面常常用到的HWND等诸多句柄QT ...
- Android listview.item.clear()与listview.clear()的区别
listview.clear()与listview.item.clear()的区别就是使用了listview.item.clear()后,listview控件中仍然保存着listviewitem项的结 ...