代码如下:

布局一:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:orientation="vertical"><EditText
        android:id="@+id/name1"
        android:hint="输入你的姓名"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /><EditText
        android:id="@+id/name2"
        android:hint="输入你喜欢的人的姓名"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /><Button
        android:text="测姻缘"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="click"/></LinearLayout>

布局二:

<?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">
<TextView
    android:id="@+id/ceshi"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

MainActivity.java:

package com.caozhihong.dell.test2;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.EditText;public class MainActivity extends AppCompatActivity {private EditText etYourName;private EditText etOtherNmae;String yourname;String othername;@Override
        protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);etYourName=(EditText)findViewById(R.id.name1);etOtherNmae=(EditText)findViewById(R.id.name2);}public void click(View v){Intent intent=new Intent();intent.putExtra("yourname",etYourName.getText().toString());intent.putExtra("othername",etOtherNmae.getText().toString());intent.setClass(MainActivity.this,Activity2.class);startActivity(intent);}
}



Activity2.java:

package com.caozhihong.dell.test2;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;import java.util.Random;/**
 * Created by dell on 2016/1/3.
 */
public class Activity2 extends Activity {private TextView tvyinyuan;@Override
    protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.layout2);tvyinyuan=(TextView)findViewById(R.id.ceshi);Intent intent=getIntent();String yourName=intent.getStringExtra("yourname");String otherName=intent.getStringExtra("othername");Random random=new Random();int num=random.nextInt(100);tvyinyuan.setText(yourName+"  "+otherName+"  "+num);}
}
总结:

1.

setContentView(R.layout.activity_main);

通过”setContentView”将布局添加进onCreate函数中。

2.声明EditText类型的etYourName及etOtherName用来联系布局中的EditText。

3.通过

etYourName=(EditText)findViewById(R.id.name1);
etOtherNmae=(EditText)findViewById(R.id.name2);绑定etYourName及etOtherName的内容。
4.通过
android:onClick="click"语句及编写子函数
public void click(View v){Intent intent=new Intent();intent.putExtra("yourname",etYourName.getText().toString());intent.putExtra("othername",etOtherNmae.getText().toString());intent.setClass(MainActivity.this,Activity2.class);startActivity(intent);
}              
实现按钮。
5.其中intent的意思为“意图”,通过创建intent对象可以实现很多功能。
6.通过intent.setClass(MainActivity.this,Activity2.class);可以将两个功能界面联系起来。
7.通过startActivity(intent);启动Activity2。

8.Activity2中,通过
private TextView tvyinyuan;语句,配合后面的tvyinyuan.setText(yourName+"  "+otherName+"  "+num);语句,打印出输出结果。

9.通过
Random random=new Random();
int num=random.nextInt(100);语句,产生出随机数num。
10.
MainActivity中的private EditText etYourName;    和    String yourname; 和 intent.putExtra("yourname",etYourName.getText().toString()); 以及Activity中的 String yourName=intent.getStringExtra("yourname");  四条语句的作用是将名字传递。

注意:
1.添加包。
2.在manifests中注册Activity2:
<activity android:name=".Activity2"></activity>

												

Activity(测姻缘总结)相关推荐

  1. 用计算机测缘分,用两人的姓名测姻缘 免费测试两个人的缘分

    佛说姻缘不可强求 佛说为何姻缘迟迟不来 现如今经济发展水平相当之快,人手一个手机已经变得并不稀奇了,不知道到大家有没有上网查看一些有趣信息的习惯,身边很多人都会说起看到一些关于佛说的经典语录,比如佛说 ...

  2. Java代码实现测姻缘

    Java代码实现测姻缘 package com.ynlg.test; import java.util.*; public class Marriage {public class Demo10 {p ...

  3. KMP(字符串匹配)+字符串哈希

    KMP非常不好理解,建议在网上搜KMP的视频看看,反正非常难理解,我想了好久好久(KMP的关键就在于求Next数组D,求前缀后缀) 下面的D题,B题稍稍有变化 ,C题只用求前缀后缀就只用求next数组 ...

  4. 公历1984年2月3日23时什么时候能嫁出去

    求测姻缘 想知道什么时候嫁人 老公怎么样? 请各位老师帮忙指点 必详细反馈 姓 名: 出生地:汕头 排盘方式:普通方式排盘 公 历:1984年2月3日23时32分 真太阳出生时间:1984-2-3 2 ...

  5. 那个给三千人算命的大师,正在给自己水滴筹

    文/陈宇航 来源/螳螂财经(ID:TanglangFin) 信星座.转锦鲤,年轻人的玩法越来越野了. 他们熟练掌握星座运势,随时随地转发锦鲤,一个个真的很爱"玄学".他们一边坚定地 ...

  6. 【Android】Activity生命周期(亲测)

    测试手机:Nexus 5   系统:4.4 一.测试 测试代码: 1 package com.example.androidalarm; 2 3 import android.app.Activity ...

  7. 测桃花运(算姻缘)的网站系统源码

    简介: 站长安装本源码后只要有人在线测算,就可以获得收入哦.是目前市面上最火的变现利器. 本版本无后台,无数据.本版本为开发的逗号联盟接口版本.直接对接逗号联盟,修改ID就可以直接运营收费赚钱. 安装 ...

  8. 深入理解Activity启动流程(三)–Activity启动的详细流程2

    本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 本系列博客将详细阐述Activity的启动流程,这些博客基于Cm 10.1源码研究. 深入理解Activity启动流程(一)--A ...

  9. android:activity的生命周期及它们之间的传值

    由于本人是个菜鸟,所以肯定会有很多理解不透测的地方,如有错误,敬请见谅..... 首先我们看一下activity的方法...... 1.启动Activity:系统会先调用onCreate方法,然后调用 ...

最新文章

  1. 彻底解决Linux索引节点(inode)占用率高的告警
  2. GO库安装报错解决:unrecognized import path golang.org/x/net (https fetch: dial tcp i/o timeout
  3. Reading——简约至上
  4. CodeForces - 1265D Beautiful Sequence(贪心+构造+思维)
  5. 吃鸡电脑配置清单_2020电脑配置游戏装机清单(覆盖主流游戏)
  6. mysql 集成模式_mysql基础学习整合
  7. opencv-api fitEllipse
  8. 用于磁盘I / O性能SQL Server监视工具
  9. nginx 启动报错 “/var/run/nginx/nginx.pid“ failed” 解决方法
  10. 自己封装的一个模拟下拉列表的插件
  11. 2022国产WMS仓库管理系统排名
  12. 微信朋友圈怎么发GIF
  13. matlab n次贝塞尔曲线
  14. Cisco命令合集-1
  15. vue3使用datav
  16. 麻雀要革命2 第8节:莽撞的麻雀小姐
  17. SAP 必须参照采购申请创建采购订单的配置方法
  18. java支持wingdings吗,[转]往JRE里添加新字体
  19. 牛逼的架构师是怎么炼成的?——阅读笔记03
  20. 计算机网络——数字数据的数字编码

热门文章

  1. mii-tool命令手册
  2. 在CMD命令行下对ntfs分区文件夹权限的设置
  3. windows cmd删除指定文件夹下指定时间文件
  4. win10设备管理没有android,win10电脑不能识别安卓设备怎么办_win10电脑识别不了安卓设备的解决方法...
  5. 简单瞎搞题(简单dp)
  6. 我的世界哪个服务器有无限手套,我的世界:MC独有的六大源石代表生物,玩家:就差无限手套了...
  7. nginx 二次修改https 反向代理服务器失败
  8. [附源码]Python计算机毕业设计Django葡萄酒销售管理系统论文
  9. Git Pull Failed
  10. 机器学习——感知机学习算法