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. 上海做假证t

    上海做假证[电/薇:187ヘ1184ヘ0909同号]办各类证件-办毕业证-办离婚证,办学位证书,办硕士毕业证,办理文凭学历,办资格证,办房产证不. 这是一个简单的取最大值程序,可以用于处理 i32 数 ...

  2. SSM框架之mybatis极速入门!

  3. 保存vuex状态刷新不消失

    写在App.vue中,所有页面共享此方法 export default { name: "app", components: {}, created() { // 页面每次刷新加载 ...

  4. Cypress系列(44)- 命令行运行 Cypress

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 前面也介绍过 Cypress 命令 ...

  5. 05_Python的文件操作

    1.文件操作概述 # 文件是用于数据存储的单位通常用来长期存储设置,文件中的数据是以字节为单位进行顺序存储的     1.打开文件: f = open("xxx") 或 with ...

  6. 机器学习,详解SVM软间隔与对偶问题

    今天是机器学习专题的第34篇文章,我们继续来聊聊SVM模型. 我们在上一篇文章当中推导了SVM模型在硬间隔的原理以及公式,最后我们消去了所有的变量,只剩下了\(\alpha\).在硬间隔模型当中,样本 ...

  7. H5选择器

    1.标签选择器 注意点:1. 标签选择器选中当前所有的标签,而不能单独选择某个标签 2.标签选择器不无多深都能被选中     3.只要是HTML中的标签就可以作为表亲啊选择器(h/a/img/ul/o ...

  8. 编写高效优雅Java程序

    面向对象 01.构造器参数太多怎么办? 如果参数很多,会导致构造方法非常多,拓展性差,代码难编写,且难以看懂. 用JavaBeans模式, get和set 一行构造编程多行代码实现,需要使用额外机制确 ...

  9. 哪些方法可以绕过PowerShell Execution Policy?

    哪些方法可以绕过PowerShell Execution Policy? 转: https://blog.csdn.net/qq_27446553/article/details/50577296

  10. Java Web制作登录 验证码

    具体操作如下: 新建一个servlet,代码如下:标记一个WebServlet, @WebServlet(urlPatterns = {"/checkCode"}) //验证码Se ...