1.多个Activity界面实现数据的传递

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#565968"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="用户名:"/> <EditText
android:id="@+id/et1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/tv1"
/> <TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="密码:"
android:layout_below="@id/tv1"/> <EditText
android:id="@+id/et2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/tv1"
android:layout_toRightOf="@id/tv1"
android:layout_marginTop="10dp"
/> <TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别:"
android:layout_below="@id/tv2"
android:layout_marginTop="29dp"/> <RadioGroup
android:id="@+id/rg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/tv2"
android:layout_toRightOf="@id/tv3"
android:layout_marginTop="25dp"> <RadioButton
android:id="@+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"/> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"/> </RadioGroup> <TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱好:"
android:layout_below="@id/tv3"
android:layout_marginTop="29dp"/> <CheckBox
android:id="@+id/ping-pong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="乒乓球"
android:textSize="12dp"
android:layout_below="@id/tv4"
/> <CheckBox
android:id="@+id/football"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="足球"
android:textSize="12dp"
android:layout_marginLeft="75dp"
android:layout_below="@id/tv4"
/> <CheckBox
android:id="@+id/volleyball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="排球"
android:textSize="12dp"
android:layout_marginLeft="135dp"
android:layout_below="@id/tv4"
/> <CheckBox
android:id="@+id/badminton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="羽毛球"
android:textSize="12dp"
android:layout_marginLeft="195dp"
android:layout_below="@id/tv4"
/> <CheckBox
android:id="@+id/basketball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="篮球"
android:textSize="12dp"
android:layout_marginLeft="265dp"
android:layout_below="@id/tv4"
/> <Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textColor="#896526"
android:layout_below="@id/tv4"
android:layout_marginTop="100dp"
android:layout_marginLeft="120dp"
android:onClick="click"/> </RelativeLayout> </androidx.constraintlayout.widget.ConstraintLayout>

  

package com.example.myhomework4;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void click(View view){ Intent it1=new Intent(this,SecondActivity.class);
String username = ((EditText)findViewById(R.id.et1)).getText().toString();
String password = ((EditText)findViewById(R.id.et2)).getText().toString();
it1.putExtra("username", username);
it1.putExtra("password", password); RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rg1);
int id = radioGroup.getCheckedRadioButtonId();
if(id == R.id.boy)
{
it1.putExtra("sex","男");
}
else
{
it1.putExtra("sex","女");
} CheckBox checkBox1 = (CheckBox)findViewById(R.id.ping_pong);
CheckBox checkBox2 = (CheckBox)findViewById(R.id.football);
CheckBox checkBox3 = (CheckBox)findViewById(R.id.volleyball);
CheckBox checkBox4 = (CheckBox)findViewById(R.id.badminton);
CheckBox checkBox5 = (CheckBox)findViewById(R.id.basketball);
if(checkBox1.isChecked()) {
it1.putExtra("ping-pong","乒乓球");
}
if (checkBox2.isChecked()) {
it1.putExtra("football","足球");
}
if(checkBox3.isChecked()) {
it1.putExtra("volleyball", "排球");
}
if(checkBox4.isChecked()) {
it1.putExtra("badminton", "羽毛球");
}
if (checkBox5.isChecked()){
it1.putExtra("basketball","篮球");
} startActivity(it1);
} }

  

package com.example.myhomework4;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast; public class SecondActivity extends Activity { @Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
String username = intent.getStringExtra("username");
String password = intent.getStringExtra("password");
String sex = intent.getStringExtra("sex");
String pingpong ="";
String football ="";
String volleyball ="";
String badminton ="";
String basketball ="";
if(intent.getStringExtra("ping-pong") != null)
{
pingpong = intent.getStringExtra("ping-pong");
}
if(intent.getStringExtra("football") != null)
{
football = intent.getStringExtra("football");
}
if(intent.getStringExtra("volleyball") != null)
{
volleyball = intent.getStringExtra("volleyball");
}
if(intent.getStringExtra("badminton") != null)
{
badminton = intent.getStringExtra("badminton");
}
if(intent.getStringExtra("basketball") != null)
{
basketball = intent.getStringExtra("basketball");
} Toast.makeText(this, "您好,您的注册信息是:\n\n" + "用户名:" + username + "\n密码:" + password + "\n性别:"
+ sex + "\n爱好:" + pingpong + football + volleyball + badminton + basketball, Toast.LENGTH_SHORT).show();
}
}

  

Android作业10/07的更多相关文章

  1. 团队作业10——事后分析(Beta版本)

    团队作业10--事后分析(Beta版本) 目录 一.设想与目标 二.计划 三.资源 四.变更管理 五.设计与实现 六.测试与发布 七.总结 八.图片和贡献分分配 一.设想和目标 1.我们的软件要解决什 ...

  2. 【2017集美大学1412软工实践_助教博客】团队作业10——项目复审与事后分析(Beta版本)

    写在前面的话 转眼轰轰烈烈本学期的软工实践就结束了,这个过程中想必在熬夜敲代码,激烈讨论中留下诸多回忆的同时,也收获了不少.恭喜所有团队完成了本阶段冲刺,此外,由于大家的贡献分给的都很平均,将个人贡献 ...

  3. 【1414软工助教】团队作业10——复审与事后分析(Beta版本) 得分榜

    题目 团队作业10--复审与事后分析(Beta版本) 往期成绩 个人作业1:四则运算控制台 结对项目1:GUI 个人作业2:案例分析 结对项目2:单元测试 团队作业1:团队展示 团队作业2:需求分析& ...

  4. 简单计算器 安卓 Android 作业

    Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...

  5. Xamarin.Android 4.10.01068 & Xamarin.iOS 1.8.361

    Xamarin.Android 4.10.01068 & Xamarin.iOS 1.8.361 NEW support for Visual Studio 2013 & Portab ...

  6. 【集美大学1411_助教博客】团队作业10——项目复审与事后分析(Beta版本)

    写在前面的话 软件工程课结束了,大家开心吗?是不是再也不用熬夜写代码了?如果这门课你真的熬夜写代码了,相信你一定有收获,如果这门课结束了你觉得是自己一个全新的开始,那么这门课的意义就实现了.团队作业全 ...

  7. 团队作业10——项目复审与事后分析(Beta版本)

    油炸咸鱼24点APP 团队作业10--事后诸葛亮分析; 团队作业10--Beta阶段项目复审;

  8. 团队作业10——复审和事后分析(Beta版本)

    团队作业10--事后分析(Beta版本) http://www.cnblogs.com/newteam6/p/6953992.html 团队作业10--复审(Beta版本) http://www.cn ...

  9. C语言|博客作业10

    问题 回答 C语言 博客作业10 这个作业要求在哪里 作业要求 我在这个课程的目标是 熟练循环语句的用法 这个作业在哪个具体方面帮助我实现目标 pta作业 参考文献 <C语言程序设计> 1 ...

随机推荐

  1. uniapp 获取元素高度 距离顶部高度等

    let _this=this let height="" const query = uni.createSelectorQuery() query.select('#u-drop ...

  2. 浅谈HASH长度拓展攻击

    前言 最近在做CTF题的时候遇到这个考点,想起来自己之前在做实验吧的入门CTF题的时候遇到过这个点,当时觉得难如看天书一般,现在回头望去,仔细琢磨一番感觉也不是那么难,这里就写篇文章记录一下自己的学习 ...

  3. Jmeter 断言-检查点

    1. http请求/添加/断言/响应断言 2. 输入一个返回数据里没有的参数 3.果然报错了 断言的作用是用来查看接口文档里是否有自己想要的数据!

  4. 让document.write的广告无阻塞的加载

    广告代码分析 很多第三方的广告系统都是使用document.write来加载广告,如下面的一个javascript的广告链接. 1 <script type="text/javascr ...

  5. IDEA中Javaweb项目图片加载不出来解决方案

    针对IDEA中Javaweb项目中无法加载图片 一.项目的结构及问题介绍 项目结构如下: 在500.jsp页面中访问了img目录下的相关图片,比如背景图片,我在500.jsp中是这样写的路径  bac ...

  6. python之读取yaml数据

    一.yaml简介 yaml:一种标记语言,专门用来写配置文件. 二.yaml基础语法 区分大小写: 使用缩进表示层级关系: 使用空格键缩进,而非Tab键缩进 缩进的空格数目不固定,只需要相同层级的元素 ...

  7. 刀哥多线程自动释放池autoreleasepool

    自动释放池 作用 自动释放对象的 所有 autorelease 的对象,在出了作用域之后,会被自动添加到最近创建的自动释放池中 自动释放池被销毁或者耗尽时,会向池中所有对象发送 release 消息, ...

  8. [剑指Offer]33-根据后序序列判断是否能组成BST

    题目 如题. 题解 从序列第一个大于根节点的值往后都是右子树,判断右子树是否都大于根节点. 然后递归判断左右子树是否是BST 代码 class TreeNode { int val = 0; Tree ...

  9. JavaCV与OpenCV的区别和使用中遇到的问题

    写这篇随笔的原因是因为我用了JavaCV一段时间后项目情况糟透了,可能大家很熟悉OpenCV,也有一部分人熟悉JavaCV,但是我相信真正把JavaCV用到生产上的不是太多. 我参与图片处理项目快一个 ...

  10. Bootstrap学习第二天轮播插件

    Bootstrap不仅提供了整套的样式,还提供了一系列插件,帮助开发者构建更受欢迎的网站. Bootstrap的轮播插件用起来很简单,代码如下. <!DOCTYPE html> <h ...