【快速解决】实验三 简单注册的实现《Android程序设计》实验报告

news2024/9/28 1:18:01

目录

前言 

实验要求

实验三 简单注册的实现

实验目的:

实验内容:

实验提示: 无

三、遇到的问题总结(如果有问题,请总结。如果没问题请写“无”)

正文开始

第一步建立项目

 第二步选择empty views activity点击next

​编辑

 第三步起名字,点击finish

第四步对 activity _main.xml文件操作进行布局

第五步,建立两个新文件,建立方法如下

LoadingActivity.java中的代码

 ResultActivity.java中的代码

activity_loading.xml代码 

 activity result.xml代码 

 MainActivity.java代码

结语 


前言 

不会写《Android程序设计》实验报告没关系,小光手把手教你怎么写。

下来我们先看一下,这次老师布置的实验要求(●'◡'●)

实验要求

实验三 简单注册的实现

实验环境:Android Studio

实验目的:
  1. 熟悉Android常见界面控件的使用,能够熟练掌握至少七种常见控件。
  2. 在自己搭建的开发环境完成一个注册页面的效果。
实验内容:

请按照以下要求完成操作,要求如下:

  1. 通过简单控件实现一个类似注册界面的效果;本界面为参考页面样式。

最少实现七种控件,其中涉及至少2个页面:

  1. 文本必选:TextView、EditText
  2. 图片二选一:ImageView、ImageButton
  3. 按钮必选:Button、RadioButton、CheckBox
  4. 可选:togglebutton
  5. 进度条三选一:ProgressBar、SeekBar、RatingBar

实验提示: 无
  • 程序源代码(只贴 .java和对应的.xml程序)

  • 运行结果界面
三、遇到的问题总结(如果有问题,请总结。如果没问题请写“无”)

注意:

 这篇文章中小光会带你们将老师布置的实验内容这部分,详细的讲解一下,大家可以直接复制代码,也可以学习一下怎么写,在这个基础上加以拓展,这样就不会查重了。

正文开始

小光的文章百分百可以成功!得到了大家的广泛认可

第一步建立项目

 第二步选择empty views activity点击next
 第三步起名字,点击finish

见到下面的页面我们的项目就算新建成功了 (是不是很简单),下来让我们开始,进行实验内容的实现。

第四步对 activity _main.xml文件操作进行布局

 老师要求我们的布局是长这个样子的,我们看一下👇👇👇

我知道大家肯定不会对页面进行布局,那我们就废话不多说,这里直接复制我帮大家写好的布局即可。

下面展示一下我的布局

 activity _main.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"
    android:padding="10dp"
    android:background="@drawable/bk">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="50dp">

        <ImageButton
            android:id="@+id/weixin"
            android:layout_width="0dp"
            android:layout_height="91dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/qq"
            android:contentDescription="微信注册" />

        <ImageButton
            android:id="@+id/qq"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:background="@drawable/weixin"
            android:contentDescription="QQ注册" />

    </LinearLayout>

    <Button
        android:id="@+id/dianzi"
        android:layout_width="378dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/bg_username"
        android:text="使用电子邮箱注册"
        android:textColor="#FFFFFF"
        android:textSize="18sp"
        android:layout_marginTop="5dp"/>

    <EditText
        android:id="@+id/et_username"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="用户名"
        android:textColor="#00FFA1"
        android:textSize="16sp"
        android:maxLines="1"
        android:padding="10dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/bg_transparent"/>

    <EditText
        android:id="@+id/et_password"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="密码"
        android:textColor="#00FFA1"
        android:textSize="16sp"
        android:maxLines="1"
        android:padding="10dp"
        android:inputType="textPassword"
        android:background="@drawable/bg_transparent"
        android:layout_marginTop="25dp"/>

    <RadioGroup
        android:id="@+id/rg_gender"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="50dp">

        <TextView
            android:id="@+id/tv_gender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="性别:"
            android:textColor="#FFFFFF"
            android:textSize="20sp"/>

        <RadioButton
            android:id="@+id/rb_male"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            android:textColor="#FFFFFF"/>

        <RadioButton
            android:id="@+id/rb_female"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女"
            android:textColor="#FFFFFF"/>

    </RadioGroup>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp">

        <TextView
            android:id="@+id/tv_hobby"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="兴趣爱好:"
            android:textColor="#FFFFFF"
            android:textSize="20sp"/>

        <CheckBox
            android:id="@+id/checkbox_sing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="唱歌"
            android:textColor="#FFFFFF"/>

        <CheckBox
            android:id="@+id/checkbox_dance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="跳舞"
            android:textColor="#FFFFFF"/>

        <CheckBox
            android:id="@+id/checkbox_read"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="读书"
            android:textColor="#FFFFFF"/>

    </LinearLayout>

    <Button
        android:id="@+id/btn_submit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/but_1"
        android:text="提交"
        android:textColor="#FFFFFF"
        android:textSize="18sp"/>

</LinearLayout>

 然后你们看到的就会是这个结果,不要怕,小光会带你们解决

问题就算这样子,没有图片,还有红色报错。没关系,小光下来教大家快速解决。

 这里大家先按照下面的操作来做

(1)对着图片新建立xml文件

最终建立好后的样子是这样的,这里注意文件名一定要一模一样

这里建立好文件就行了,(为了方便大家)文件里面什么都不用写。这样 activity _main.xml就可以找到我们代码中的文件了。

这样要是大家相加布局文件中的内容我会把内容放在最后,大家直接复制就行。

然后加入背景图片(背景图片加入自己的背景图)

这里主要是文件名字要一样,这样就可以直接用了。

 这里我们加一些输入框的背景(不然都看不清了)

 对应代码如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#80CCCCCC" />
    <corners android:radius="8dp" />
</shape>

效果展示

这样我们的布局就做完了。下面的内容就非常简单了,写到这里我已经写累了,相信大家也看累了,那么下来我们就直接我能复制,加快我们的速度吧,gogogo(●'◡'●)

第五步,建立两个新文件,建立方法如下

第一个LoadingActivity 

第二个ResultActivity  

下载开始直接复制即可,无脑复制,快速结束战斗(估计要5花分钟)

LoadingActivity.java中的代码
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.os.Handler;
import android.widget.TextView;
import android.content.Intent;

public class LoadingActivity extends AppCompatActivity {

    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);

        // 获取MainActivity传递的数据
        Intent intent = getIntent();
        if (intent != null) {
            String username = intent.getStringExtra("USERNAME");
            String password = intent.getStringExtra("PASSWORD");
            String gender = intent.getStringExtra("GENDER");
            String hobbies = intent.getStringExtra("HOBBIES");

            // 在这里可以根据需要使用这些数据

            // 显示ProgressBar
            progressBar = findViewById(R.id.progress_bar);

            // 在onCreate中添加
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    // 跳转到ResultActivity并传递数据
                    Intent resultIntent = new Intent(LoadingActivity.this, ResultActivity.class);
                    resultIntent.putExtra("USERNAME", username);
                    resultIntent.putExtra("PASSWORD", password);
                    resultIntent.putExtra("GENDER", gender);
                    resultIntent.putExtra("HOBBIES", hobbies);
                    startActivity(resultIntent);

                    // 关闭当前Loading页面
                    finish();
                }
            }, 3000); // 延迟3秒
        }
    }
}

 复制完后会看见这样子

 ResultActivity.java中的代码
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;
import android.content.Intent;

public class ResultActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);

        // 获取传递的数据
        Intent intent = getIntent();
        if (intent != null) {
            String username = intent.getStringExtra("USERNAME");
            String password = intent.getStringExtra("PASSWORD");
            String gender = intent.getStringExtra("GENDER");
            String hobbies = intent.getStringExtra("HOBBIES");

            // 将数据显示在 TextView 中
            TextView textUsername = findViewById(R.id.text_username);
            TextView textPassword = findViewById(R.id.text_password);
            TextView textGender = findViewById(R.id.text_gender);
            TextView textHobbies = findViewById(R.id.text_hobbies);

            textUsername.setText("Username: " + username);
            textPassword.setText("Password: " + password);
            textGender.setText("Gender: " + gender);
            textHobbies.setText("Hobbies: " + hobbies);
        }
    }
}

activity_loading.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"
    android:gravity="center">

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="加载中..."/>

</LinearLayout>

 activity result.xml代码 

 

<!-- activity_result.xml -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <TextView
        android:id="@+id/text_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username: "
        android:textSize="18sp"
        android:textColor="#000000"/>

    <TextView
        android:id="@+id/text_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password: "
        android:textSize="18sp"
        android:textColor="#000000"/>

    <TextView
        android:id="@+id/text_gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Gender: "
        android:textSize="18sp"
        android:textColor="#000000"/>

    <TextView
        android:id="@+id/text_hobbies"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hobbies: "
        android:textSize="18sp"
        android:textColor="#000000"/>
</LinearLayout>

 MainActivity.java代码
package com.example.myapplication;

import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.os.SystemClock;

public class MainActivity extends AppCompatActivity {
    private EditText etUsername, etPassword;
    private RadioGroup rgGender;
    private RadioButton rbMale, rbFemale;
    private CheckBox checkboxSing, checkboxDance, checkboxRead;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化视图
        etUsername = findViewById(R.id.et_username);
        etPassword = findViewById(R.id.et_password);
        rgGender = findViewById(R.id.rg_gender);
        rbMale = findViewById(R.id.rb_male);
        rbFemale = findViewById(R.id.rb_female);
        checkboxSing = findViewById(R.id.checkbox_sing);
        checkboxDance = findViewById(R.id.checkbox_dance);
        checkboxRead = findViewById(R.id.checkbox_read);

        // 假设有一个按钮点击事件触发传递数据到 ResultActivity
        Button submitButton = findViewById(R.id.btn_submit);
        submitButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取输入的文本
                String username = etUsername.getText().toString();
                String password = etPassword.getText().toString();

                // 获取选中的性别
                String gender = "";
                int selectedId = rgGender.getCheckedRadioButtonId();
                if (selectedId == R.id.rb_male) {
                    gender = "男";
                } else if (selectedId == R.id.rb_female) {
                    gender = "女";
                }

                // 获取选中的兴趣爱好
                StringBuilder hobbies = new StringBuilder();
                if (checkboxSing.isChecked()) {
                    hobbies.append("唱歌 ");
                }
                if (checkboxDance.isChecked()) {
                    hobbies.append("跳舞 ");
                }
                if (checkboxRead.isChecked()) {
                    hobbies.append("读书");
                }

                // 创建一个Intent传递数据到ResultActivity
                Intent intent = new Intent(MainActivity.this, LoadingActivity.class);
                intent.putExtra("USERNAME", username);
                intent.putExtra("PASSWORD", password);
                intent.putExtra("GENDER", gender);
                intent.putExtra("HOBBIES", hobbies.toString());

                // 启动 ResultActivity
                startActivity(intent);
            }
        });
    }
}

 很好,复制到这里,你的实验就算是完成了,接下来让我们运行看看效果吧

点击运行 

这样就结束了,感谢大家的观看,百分百成功,不会出现运行不了的问题。但一定要按照小光的代码复制,全部复制粘贴就行了。这里强调一下,文件的名字,所有的名字必须都和展示的图片中一模一样,不然会报错。

结语 

关注小光,小光帮你写实验报告(不是真的帮你写,就是我写好,你直接复制拿走的那种)也可以看看小光的其他文章,小光是全能的。

🌌点击下方个人名片,交流会更方便哦~(欢迎到博主主页加入我们的 CodeCrafters联盟一起交流学习↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓   

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1223121.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux-top命令解释

Linux-top命令解释 常用参数查看所有逻辑核的运行情况&#xff1a;1查看指定进程的情况&#xff1a;-p pid显示进程的完整命令&#xff1a;-c 面板指标解释第一行top第二行tasks第三行%Cpu第四行Mem第五行Swap第六行各进程监控PID&#xff1a;进程IDUSER&#xff1a;进程所有者…

什么是BT种子!磁力链接又是如何工作的?

目录 一.什么是BT&#xff1f;1.BT简介&#xff1a;1.1.BT是目前最热门的下载方式之一1.2.BT服务器是通过一种传销的方式来实现文件共享的 2.小知识&#xff1a;2.1.你知道吗BT下载和常规下载到底有哪些不同2.2.BT下载的灵魂&#xff1a;种子2.3.当下载结束后&#xff0c;如果未…

Redis维护缓存的方案选择

Redis中间件常常被用作缓存&#xff0c;而当使用了缓存的时候&#xff0c;缓存中数据的维护&#xff0c;往往是需要重点关注的&#xff0c;尤其是重点考虑的是数据一致性问题。以下是维护数据库缓存的一些常用方案。 1、先删除缓存&#xff0c;再更新数据库 导致数据不一致的…

vulnhub靶机Momentum

下载地址&#xff1a;https://download.vulnhub.com/momentum/Momentum.ova 主机发现 目标192.168.21.129 端口扫描 端口版本扫描 漏洞扫描 扫出来点目录简单看看 发现js里面有一点东西 这里面告诉了我们了web文件有id传值&#xff0c;而且有aes加密还有密钥 跟二没有啥区别&…

ai的潜力和中短期的未来预测

内容来源&#xff1a;rickawsb ​对于描述ai的潜力和中短期的未来预测&#xff0c;我认为到目前为止可能没有比这篇推文总结得更好的了。 我读了三次。 文章起源于一个用户感叹openai升级chatgpt后&#xff0c;支持pdf上传功能&#xff0c;直接让不少的靠这个功能吃饭的创业公…

FISCOBCOS入门(十)Truffle测试helloworld智能合约

本文带你从零开始搭建truffle以及编写迁移脚本和测试文件,并对测试文件的代码进行解释,让你更深入的理解truffle测试智能合约的原理,制作不易,望一键三连 在windos终端内安装truffle npm install -g truffle 安装truffle时可能出现网络报错,多试几次即可 truffle --vers…

CTFhub-RCE-综合过滤练习

%0a、%0d、%0D%0A burp 抓包 修改请求为 POST /?127.0.0.1%0als 列出当前目录 返回包 http://challenge-135e46015a30567b.sandbox.ctfhub.com:10800/?ip127.0.0.1%0acd%09*here%0ac%27a%27t%09* _311632412323588.php

YOLOv8独家改进: Inner-IoU基于辅助边框的IoU损失,高效结合 GIoU, DIoU, CIoU,SIoU 等 | 2023.11

💡💡💡本文独家改进:Inner-IoU引入尺度因子 ratio 控制辅助边框的尺度大小用于计算损失,并与现有的基于 IoU ( GIoU, DIoU, CIoU,SIoU )损失进行有效结合 推荐指数:5颗星 新颖指数:5颗星 💡💡💡Yolov8魔术师,独家首发创新(原创),适用于Yolov5…

苍穹外卖--员工分页查询

请求参数封装&#xff1a; Data public class EmployeePageQueryDTO implements Serializable {//员工姓名private String name;//页码private int page;//每页显示记录数private int pageSize;}请求结果封装&#xff1a; public class PageResult implements Serializable {…

完整版解答!2023年数维杯国际大学生数学建模挑战赛B题

B题完整版全部5问&#xff0c;问题解答、代码&#xff0c;完整论文、模型的建立和求解、各种图表代码已更新&#xff01; 大家好&#xff0c;目前已完成2023数维杯国际赛B题全部5问的代码和完整论文已更新&#xff0c;部分展示如下&#xff1a; 部分解答图表 问题分析 B题前三…

c++中的String

文章目录 String定义对象的方式成员函数operatorbegin/endsizecapacityreserversizeoperator/append/push_backoperator[]/at String String是一个类模版&#xff0c;可以定义一个字符/字符串对象。 字符顺序表 定义对象的方式 定义方式有很多重要的就这几种 string s1;stri…

屏蔽bing搜索框的今日热点

中国版的Bing简直比百度还恶心了&#xff0c;“今日热点”要是在搜索设置里关闭了就没法提供搜索建议了&#xff0c;不关吧看着又烦人&#xff0c;就像下图这样。另外还有右上角的下载bing app和Rewards图标也闲着没啥用&#xff0c;Rewards图标还老有小红点&#xff0c;真受不…

【C++】类和对象(5)--运算符重载

目录 一 概念 二 运算符重载的实现 三 关于时间的所有运算符重载 四 默认赋值运算符 五 const取地址操作符重载 一 概念 C为了增强代码的可读性引入了运算符重载&#xff0c;运算符重载是具有特殊函数名的函数&#xff0c;也具有其返回值类型&#xff0c;函数名字以及参数…

实验六:Android的网络编程基础

实验六&#xff1a;Android 的网络编程基础 6.1 实验目的 本次实验的目的是让大家熟悉 Android 开发中的如何获取天气预报&#xff0c;包括了 解和熟悉 WebView、WebService 使用、网络编程事件处理等内容。 6.2 实验要求 熟悉和掌握 WebView 使用 了解 Android 的网络编程…

cs与msf联动

实验环境 cs4.4(4.5版本不知道为啥实现不了) cs服务器与msf在同一台vps上 本地win7虚拟机 cs派生会话给msf 首先cs正常上线win7&#xff0c;这就不多说了&#xff0c;然后说如何将会话派生给msf cs准备 选择Foreign&#xff0c;这里可以选HTTP&#xff0c;也可以选HTTPS…

LLM大模型权重量化实战

大型语言模型 (LLM) 以其广泛的计算要求而闻名。 通常&#xff0c;模型的大小是通过将参数数量&#xff08;大小&#xff09;乘以这些值的精度&#xff08;数据类型&#xff09;来计算的。 然而&#xff0c;为了节省内存&#xff0c;可以通过称为量化的过程使用较低精度的数据类…

庖丁解牛:NIO核心概念与机制详解

文章目录 Pre输入/输出Why NIO流与块的比较通道和缓冲区概述什么是缓冲区&#xff1f;缓冲区类型什么是通道&#xff1f;通道类型 NIO 中的读和写概述Demo : 从文件中读取1. 从FileInputStream中获取Channel2. 创建ByteBuffer缓冲区3. 将数据从Channle读取到Buffer中 Demo : 写…

基于静电放电算法优化概率神经网络PNN的分类预测 - 附代码

基于静电放电算法优化概率神经网络PNN的分类预测 - 附代码 文章目录 基于静电放电算法优化概率神经网络PNN的分类预测 - 附代码1.PNN网络概述2.变压器故障诊街系统相关背景2.1 模型建立 3.基于静电放电优化的PNN网络5.测试结果6.参考文献7.Matlab代码 摘要&#xff1a;针对PNN神…

JVM:字节码文件,类的生命周期,类加载器

JVM&#xff1a;字节码文件&#xff0c;类的生命周期&#xff0c;类加载器 为什么要学这门课程 1. 初识JVM1.1. 什么是JVM1.2. JVM的功能1.3. 常见的JVM 2. 字节码文件详解2.1. Java虚拟机的组成2.2. 字节码文件的组成2.2.1. 以正确的姿势打开文…

电脑软件:推荐一款非常实用的固态硬盘优化工具

目录 一、软件简介 二、工作原理 三、功能介绍 3.1、优化SSD设置 3.2、查看驱动器信息 3.3、查看SMART数据 3.4、停用Windows事件日志记录 3.5、禁用Windows碎片整理 3.6、时间戳停用 3.7、禁用引导文件的碎片整理 3.8、关闭短名称 四、使用教程 4.1 安装说明 4.…