首页 > 其他分享 >3.9

3.9

时间:2024-06-19 17:36:25浏览次数:11  
标签:findViewById private student import android id 3.9

所花时间:五十分钟左右,不到一个小时,今天主要是敲代码了,视频基本跳着看的

代码量:增部分的后四十行,删的37行,改的65行

了解到的知识点:

增代码

package com.example.test3_6;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import com.example.sqlitetest271.bean.Student;
import com.example.sqlitetest271.util.ToastUtil;

public class InsertActivity extends AppCompatActivity {

private EditText etName,etNumber,etScore;
private RadioButton rbMan,rbWoman;


private MySQLiteOpenHelper mMySQLiteOpenHelper;

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

initView();
mMySQLiteOpenHelper = new MySQLiteOpenHelper(this);

}

private void initView() {
etName = findViewById(R.id.et_name);
etNumber = findViewById(R.id.et_number);
etScore = findViewById(R.id.et_score);
rbMan = findViewById(R.id.rb_man);
rbWoman = findViewById(R.id.rb_woman);

}

public void insert(View view) {
String name = etName.getText().toString().trim();
String number = etNumber.getText().toString().trim();
String score = etScore.getText().toString().trim();
String gender = "";

if (rbMan.isChecked()) {
gender = "男";
}

if (rbWoman.isChecked()) {
gender = "女";
}

Student student = new Student();
student.setName(name);
student.setNumber(number);
student.setGender(gender);
student.setScore(score);

// 插入数据库中
long rowId = mMySQLiteOpenHelper.insertData(student);
if (rowId != -1) {
ToastUtil.toastShort(this, "添加成功!");
} else {
ToastUtil.toastShort(this, "添加失败!");
}

}
} 删代码 package com.example.test3_6;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.example.sqlitetest271.util.ToastUtil;

public class DeleteActivity extends AppCompatActivity {

private EditText etName;
private MySQLiteOpenHelper mMySQLiteOpenHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delete);
etName = findViewById(R.id.et_name);
mMySQLiteOpenHelper = new MySQLiteOpenHelper(this);
}

public void delete(View view) {

String name = etName.getText().toString().trim();

// 按姓名从数据库中删除

int row = mMySQLiteOpenHelper.deleteFromDbByName(name);
if (row > 0) {
ToastUtil.toastLong(this, "删除成功,删了" + row + "条数据");
}else{
ToastUtil.toastLong(this, "删除失败,没有找到符合条件的数据");
}
}
} 改代码 package com.example.test3_6;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;

import com.example.sqlitetest271.bean.Student;
import com.example.sqlitetest271.util.ToastUtil;

public class UpdateActivity extends AppCompatActivity {
private EditText etName,etNumber,etScore;
private RadioButton rbMan,rbWoman;


private MySQLiteOpenHelper mMySQLiteOpenHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update);
initView();
mMySQLiteOpenHelper = new MySQLiteOpenHelper(this);
}


private void initView() {
etName = findViewById(R.id.et_name);
etNumber = findViewById(R.id.et_number);
etScore = findViewById(R.id.et_score);
rbMan = findViewById(R.id.rb_man);
rbWoman = findViewById(R.id.rb_woman);

}

public void update(View view) {
String name = etName.getText().toString().trim();
String number = etNumber.getText().toString().trim();
String score = etScore.getText().toString().trim();
String gender = "";

if (rbMan.isChecked()) {
gender = "男";
}

if (rbWoman.isChecked()) {
gender = "女";
}

Student student = new Student();
student.setName(name);
student.setNumber(number);
student.setGender(gender);
student.setScore(score);

// 更新数据库
long rowId = mMySQLiteOpenHelper.updateData(student);
if (rowId > 0) {
ToastUtil.toastShort(this, "更新成功!");
} else {
ToastUtil.toastShort(this, "没有数据被更新!");
}
}
}

标签:findViewById,private,student,import,android,id,3.9
From: https://www.cnblogs.com/szm123/p/18256754

相关文章

  • Win11+Miniconda3+python3.9安装pyspark+pytorch
    Win11+Miniconda3+python3.9安装pyspark+pytorch步骤1:安装Miniconda3,具体可以百度或者google步骤2:安装好Miniconda3之后,要创建虚拟环境,类似于虚拟机的样子,然后在虚拟环境安装各种python包已经装好了pytorch,具体步骤可以参考网上的一些教程,很多时候要综合多个教程,比如说先建立......
  • Video Cut Crop Join for Mac(mac视频剪辑合并软件 )v3.9版
    VideoCutCropJoinforMac是一款适用于Mac用户的视频编辑软件。这款软件具有强大的功能,可以帮助用户对视频进行精准的剪切、裁剪,并将其压缩为各种小尺寸和格式,非常适合在网站上分享。VideoCutCropJoinforMac(mac视频剪辑合并软件)软件地址VideoCutCropJoinforM......
  • 酷我音乐车机版 v6.3.9.40 祛广SVIP版
    软件介绍酷我音乐车机版是一款提供无损音质歌曲免费收听和下载的应用程序。随着现代汽车内置系统的功能日益增强,除了基本的导航功能和音频播放,这些系统还支持安装各种应用程序,其中包括无广告的专业版应用。这样的设计显著提升了车载系统的功能性和用户便利性。该应用的用户......
  • 配置Tensorflow使用GPU加速(Tensorflow2.6.0,Python3.6-3.9,CUDA11.2,cuDNN8.1)
    目录前言一、安装Anaconda1.1从Anaconda官网下载Anaconda(默认安装最新版本)1.2安装Anaconda并配置环境变量二、安装CUDA和cuDNN2.1下载CUDAToolkit2.2安装CUDAToolkit2.3下载安装cuDNN2.4配置CUDA环境变量三、创建Anaconda虚拟环境并安装Tensorflow3.1创建......
  • CentOS-7.9 安装rabbitmq3.9.11 ,erlang-23.3.4.11
    下载所需rpm包wget https://github.com/rabbitmq/erlang-rpm/releases/download/v23.3.4.11/erlang-23.3.4.11-1.el7.x86_64.rpmwget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.9.11/rabbitmq-server-3.9.11-1.el7.noarch.rpm安装Erlangsu......
  • Centos8安装k8s1.23.9
    离线安装一、环境准备卸载podman关闭交换区禁用selinux关闭防火墙依赖包安装系统参数优化配置本地dockeryum源一:centos8默认安装podmanbuildah需要卸载sudoyumerasepodmanbuildah-y二:节点关闭swap分区swapoff-a&&sysctl-wvm.swappiness=0sudosed-i'......
  • Centos7部署k8s1.23.9
    !/bin/bashfunctionnode_update_kernel(){启用ELRepo仓库sudorpm--importhttps://www.elrepo.org/RPM-GPG-KEY-elrepo.orgsudorpm-Uvhhttp://www.elrepo.org/elrepo-release-7.0-6.el7.elrepo.noarch.rpm查看可用的系统内核包sudoyum--disablerepo="*"--enabl......
  • 麒麟kylin安装K8s1.23.9
    1.主机名解析10.129.148.4hangkong-k8s-node0110.129.148.5hangkong-k8s-node0210.129.148.6hangkong-k8s-node0310.129.148.4hangkong-k8s.vip.com2.主机名设置echo'hangkong-k8s-node01'>/etc/hostnameecho'hangkong-k8s-node02'>/etc/hos......
  • 麒麟kylin-ARM安装K8s1.23.9
    第一章k8s及中间件安装1.主机名解析2.主机名设置3.禁用iptables和firewalld4.禁用selinux(linux下的一个安全服务,必须禁用)5.禁用swap分区(主要是注释最后一行)6.修改系统的内核参数7.配置ipvs功能8.安装docker验证docker安装是否成功9.安装kubernetes1.23.910.集群初始......
  • 加装zookeeper3.9.2
    点击查看代码Xshell7(Build0151)Copyright(c)2020NetSarangComputer,Inc.Allrightsreserved.Type`help'tolearnhowtouseXshellprompt.[C:\~]$Connectingto192.168.10.10:22...Connectionestablished.Toescapetolocalshell,press'C......