首页 > 其他分享 >Android-简单增删改查-初步实现主要页面

Android-简单增删改查-初步实现主要页面

时间:2023-02-25 00:34:05浏览次数:31  
标签:String 改查 public static 增删 Android final 页面

我先想做出个简单增删改查连上数据库,能把学生姓名列出来,可以添加学生数据

今天时间很紧,搁宿舍敲了半天把页面写出来了,剩下的代码还不少,一口气也做不完,我也有点熬不住了。

今天先把这个页面放出来,这部分是最简单但是有点零碎的。

今天用到的知识点有TextView  EditText Button 线性布局 相对布局 

代码

actitvty_main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".MainActivity">
 9 
10     <Button
11         android:id="@+id/btn_add"
12         android:layout_width="wrap_content"
13         android:layout_height="wrap_content"
14         android:text="添加"
15         android:layout_alignParentBottom="true"
16         android:layout_alignParentLeft="true"></Button>
17     <ListView
18         android:id="@android:id/list"
19         android:layout_width="wrap_content"
20         android:layout_height="wrap_content"
21         android:layout_above="@id/btn_add"
22         ></ListView>
23     <Button
24         android:id="@+id/btn_get"
25         android:layout_toRightOf="@id/btn_add"
26         android:layout_marginLeft="20dp"
27         android:layout_height="wrap_content"
28         android:layout_width="wrap_content"
29         android:text="显示"
30         android:layout_alignParentBottom="true"/>
31 </RelativeLayout>

预览效果

 

 actitvty_student.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent">
 5 
 6     <TextView
 7         android:layout_width="wrap_content"
 8         android:layout_height="wrap_content"
 9         android:text="姓名"
10         android:textSize="30sp"
11         android:id="@+id/tv_name"
12         android:layout_alignParentTop="true"
13         android:layout_alignParentLeft="true"
14         android:layout_alignParentStart="true"
15         android:layout_marginTop="30dp"
16         ></TextView>
17     <TextView
18         android:layout_width="wrap_content"
19         android:layout_height="wrap_content"
20         android:text="学号"
21         android:textSize="30sp"
22         android:id="@+id/tv_id"
23         android:layout_below="@+id/tv_name"
24         android:layout_alignParentLeft="true"
25         android:layout_alignParentStart="true"
26         android:layout_marginTop="20dp"
27         ></TextView>
28     <TextView
29         android:layout_width="wrap_content"
30         android:layout_height="wrap_content"
31         android:text="班级"
32         android:textSize="30sp"
33         android:id="@+id/tv_grade"
34         android:layout_below="@+id/tv_id"
35         android:layout_alignParentLeft="true"
36         android:layout_alignParentStart="true"
37         android:layout_marginTop="20dp"
38         ></TextView>
39     <EditText
40         android:layout_width="wrap_content"
41         android:layout_height="wrap_content"
42         android:id="@+id/et_name"
43         android:inputType="textPersonName"
44         android:ems="10"
45         android:layout_above="@+id/tv_id"
46         android:layout_toRightOf="@+id/tv_name"
47         android:layout_alignParentRight="true"
48         android:layout_alignParentEnd="true"
49         ></EditText>
50     <EditText
51         android:layout_width="wrap_content"
52         android:layout_height="wrap_content"
53         android:id="@+id/et_id"
54         android:inputType="textPersonName"
55         android:ems="10"
56         android:layout_above="@+id/tv_grade"
57         android:layout_toRightOf="@+id/tv_id"
58         android:layout_alignParentRight="true"
59         android:layout_alignParentEnd="true"
60         ></EditText>
61     <EditText
62         android:layout_width="wrap_content"
63         android:layout_height="wrap_content"
64         android:id="@+id/et_class"
65         android:inputType="textPersonName"
66         android:ems="10"
67         android:layout_below="@+id/tv_id"
68         android:layout_toRightOf="@+id/tv_grade"
69         android:layout_alignParentRight="true"
70         android:layout_alignParentEnd="true"
71         android:layout_marginTop="20dp"
72         ></EditText>
73     <Button
74         android:layout_width="wrap_content"
75         android:layout_height="wrap_content"
76         android:id="@+id/btn_close"
77         android:text="返回"
78         android:textSize="30dp"
79         android:layout_alignParentBottom="true"
80         android:layout_alignParentLeft="true"
81         ></Button>
82     <Button
83         android:layout_width="wrap_content"
84         android:layout_height="wrap_content"
85         android:id="@+id/btn_save"
86         android:text="保存"
87         android:textSize="30dp"
88         android:layout_toRightOf="@+id/btn_close"
89         android:layout_alignParentBottom="true"
90         android:layout_marginLeft="10dp"
91         ></Button>
92 </RelativeLayout>

预览

 

 

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical">
 6     <TextView
 7         android:layout_width="match_parent"
 8         android:layout_height="wrap_content"
 9         android:id="@+id/student_id"
10         android:visibility="gone"
11         ></TextView>
12     <TextView
13         android:layout_width="match_parent"
14         android:layout_height="wrap_content"
15         android:paddingLeft="6dp"
16         android:paddingTop="6dp"
17         android:textSize="22sp"
18         android:textStyle="bold"
19         ></TextView>
20 </LinearLayout>

还创了个student类

 1 package com.example.myapplication;
 2 
 3 public class Student {
 4 
 5     public static final String TABLE= "Student";
 6 
 7     public static final String KEY_NAME="name";
 8     public static final String KEY_ID = "id";
 9     public static final String KEY_CLASS = "grade";
10 
11     public String student_name;
12     public String id;
13     public String grade;
14 
15 }

创建表连接数据库后端实现这些今天一口气也做不出来了,先休息了。

标签:String,改查,public,static,增删,Android,final,页面
From: https://www.cnblogs.com/rsy-bxf150/p/17153620.html

相关文章

  • 【新手入门】JDBC+Servlet+jsp【新闻系统的增删改查】:持续学习,持续优化,争取做一个真正
    新闻的增删改查  学习了一些博客知识【结尾会贴上,大家可以参考】在借鉴的基础上又进行了代码的优化,从而实现了CRUD,下面分享我的代码过程:包结构,是为了方便管理,所以我......
  • android stdio中textview控件的属性
    android:id//可以通过此id找到该控件android:layout_width//宽度android:layout_height//高度android:layout_background//设置背景的颜色、图片或是其他文件复制预期图片......
  • Android 应用接入 Firebase Crashlytics 进行崩溃分析上报
    前言所在公司的项目中有一款应用应客户要求,需要接入FirebaseCrashlytics,在此提前练手,也做个总结。本文以最新的Gradle7.5为例,如果Gradle版本比较低,添加依赖那一章......
  • Android Studio-Button的学习
    今天学习了Button,也学习了Button事件,但是事件学的不好,明天会重复对Button的学习1:<Buttonandroid:text="按钮"android:background="@drawable/btn_sele......
  • Android虚拟机遇到错误无法打开的解决方法
    错误提示:因为博主已经解决此问题,所以这个图片为其他网站搬运的图片,显示安卓虚拟机无法正常打开踩坑一开始博主以为是IDE的问题,结果重装也没有用。错误原因1.安卓镜像......
  • Android 分区和内存监控
    Android分区和内存监控Andorid之所以是分区,是因为各自有对应的功能和用途的考量,可以进行单独读写和格式化。Android设备包含两类分区:一类是启动分区,对启动过程至关重......
  • Android学习-TextView和Button
    TextViewTextView即文本框,也比较简单,可以看一下,和view差不多maxLine是限制行数的,如果限制一行还字太多就会不显示ellipsize="end"可以使得多出来的字用...代替  ......
  • MySQL增删查改
    创建数据库createdatabase数据库名;查看数据库showdatabases;切换数据库use数据库名;创建表createtable表名(字段名  类型,字段名  类型,......);插......
  • Java 操作mongodb的增删改查操作
    MongoDb非关系型数据库,又称为NoSql(不仅仅是sql),主要是非关系型,分布式,不提供ACID的数据库设计模式。MongoDB是一种面向文档的数据库管理系统,支持的数据结构非常松散,是类似j......
  • unity 3d导出安卓包时报错:A failure occurred while executing com.android.build.gra
    unity3d导出安卓包时报错:Afailureoccurredwhileexecutingcom.android.build.gradle.internal.tasks.workers$actionfacadeseetheconsolefordetails如下图网......