Android实验三:通过Activity传值实现加法

本文介绍了Android编程基础实验,通过Activity实现加法运算。实验目标是学习多个Activity的开发,要求在第一个Activity输入两个整数,点击计算后在第二个Activity计算和并返回显示。代码实现中,利用Bundle和Intent进行值传递,同时提出了输入验证和Bundle方法使用的改进意见。
摘要由CSDN通过智能技术生成

1.实验讲义

实验三 Android编程基础——Activity(2课时)

一、实验目的
1、学习android程序多个Activity的开发方法。
二、实验内容
1、编写一个程序,可在第一个Activity中输入两个整数,单击“计算”按钮后,在第二个Activity负责求和计算,并将结果显示在第一个Activity中。
三、实验步骤
1、建立一个android工程,修改main.xml文件并添加新的.xml文件,修改AndroidManifest.xml文件,编写程序代码,可在第一个Activity中输入两个整数,单击“计算”按钮后,在第二个Activity中负责求和计算,并将结果传回并显示在第一个Activity中。
四、考核标准:
1、完成全部题目,设计合理,结果正确;评定为A。
2、完成部分题目,设计比较合理,结果正确;根据实际情况评定为B或C。
3、未独立完成实验要求;评定为D。

2.代码实现

2.1.文件结构

在这里插入图片描述

2.2.main界面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="请输入第一个加数" />
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="+" />
            <EditText
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
  • 4
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值