2022-11-19学习内容-Server端代码编写-Client端代码编写
1.Server端代码编写
1.1UserDBHelper.java
package com.example.chapter07_server.database; import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; public class UserDBHelper extends SQLiteOpenHelper { private static final String DB_NAME = "user.db";
public static final String TABLE_NAME = "USER_INFO";
private static final int DB_VERSION = 1;
private static UserDBHelper mHelper = null; private UserDBHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
} // 利用单例模式获取数据库帮助器的唯一实例
public static UserDBHelper getInstance(Context context) {
if (mHelper == null) {
mHelper = new UserDBHelper(context);
}
return mHelper;
} // 创建数据库,执行建表语句
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
"_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
" NAME VARCHAR NOT NULL," +
" AGE INTEGER NOT NULL," +
" HEIGHT LONG NOT NULL," +
" WEIGHT FLOAT NOT NULL," +
" MARRIED INTEGER NOT NULL);";
db.execSQL(sql);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} }
1.2UserInfoProvider.java
package com.example.chapter07_server.provider; import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log; import com.example.chapter07_server.database.UserDBHelper; public class UserInfoProvider extends ContentProvider { private UserDBHelper dbHelper; @Override
public boolean onCreate() {
Log.d("ning", "UserInfoProvider onCreate");
dbHelper = UserDBHelper.getInstance(getContext());
return true;
} // content://com.example.chapter07_server.provider.UserInfoProvider/user
@Override
public Uri insert(Uri uri, ContentValues values) {
Log.d("ning", "UserInfoProvider insert");
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.insert(UserDBHelper.TABLE_NAME, null, values);
return uri;
} @Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
Log.d("ning", "UserInfoProvider query");
SQLiteDatabase db = dbHelper.getReadableDatabase();
return db.query(UserDBHelper.TABLE_NAME, projection, selection, selectionArgs, null, null, null);
} @Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// Implement this to handle requests to delete one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
} @Override
public String getType(Uri uri) {
// TODO: Implement this to handle requests for the MIME type of the data
// at the given URI.
throw new UnsupportedOperationException("Not yet implemented");
} @Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
// TODO: Implement this to handle requests to update one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}
}
2.Client端代码编写
2.1activity_content_write.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="5dp"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"> <TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="姓名:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_weight="1"
android:background="@drawable/editext_selector"
android:hint="请输入姓名"
android:inputType="text"
android:maxLength="12"
android:text="Jack"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"> <TextView
android:id="@+id/tv_age"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="年龄:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_age"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_weight="1"
android:background="@drawable/editext_selector"
android:hint="请输入年龄"
android:inputType="number"
android:maxLength="2"
android:text="18"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"> <TextView
android:id="@+id/tv_height"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="身高:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_height"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_weight="1"
android:background="@drawable/editext_selector"
android:hint="请输入身高"
android:inputType="number"
android:maxLength="3"
android:text="180"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"> <TextView
android:id="@+id/tv_weight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="体重:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_weight"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_weight="1"
android:background="@drawable/editext_selector"
android:hint="请输入体重"
android:inputType="numberDecimal"
android:maxLength="5"
android:text="180"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout> <CheckBox
android:id="@+id/ck_married"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:gravity="center"
android:text="已婚"
android:textColor="@color/black"
android:textSize="17sp" /> <Button
android:id="@+id/btn_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="保存"
android:textColor="@color/black"
android:textSize="17sp" /> <Button
android:id="@+id/btn_read"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="读取"
android:textColor="@color/black"
android:textSize="17sp" /> <Button
android:id="@+id/btn_delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="删除"
android:textColor="@color/black"
android:textSize="17sp" /> </LinearLayout>
2022-11-19学习内容-Server端代码编写-Client端代码编写的更多相关文章
- server端获得到client端的IP地址的格式
使用telnet,ping或其他client连接server端时,server端获得的client端的ip地址取决于client端使用的时ipv4还是ipv6地址. 例: client IPv4地址: ...
- 搜集的一些RTMP项目,有Server端也有Client端
查询一些RTMP的协议封装时找到了一些RTMP开源项目,在这里列举一下,以后有时间或是有兴趣可以参考一下: just very few of them. Red5 only contains a se ...
- 使用gRPC搭建Server端与Client端
gRPC简介 gRPC是一种RPC框架技术,采用Protocal Buffers(协议缓存) 作为其接口定义的语言(就是Proto来写接口)和基础的消息交换格式. 在gRPC中,客户端应用程序可以直接 ...
- 基于Netty和SpringBoot实现一个轻量级RPC框架-Client端请求响应同步化处理
前提 前置文章: <基于Netty和SpringBoot实现一个轻量级RPC框架-协议篇> <基于Netty和SpringBoot实现一个轻量级RPC框架-Server篇> & ...
- u-boot代码学习内容
前言 u-boot代码庞大,不可能全部细读,只能有选择的读部分代码.在读代码之前,根据韦东山教材,关于代码学习内容和深度做以下预先划定. 一.Makefile.mkconfig.config.mk等 ...
- 从零开始学习Node.js例子四 多页面实现数学运算 续二(client端和server端)
1.server端 支持数学运算的服务器,服务器的返回结果用json对象表示. math-server.js //通过监听3000端口使其作为Math Wizard的后台程序 var math = r ...
- Redis:安装、配置、操作和简单代码实例(C语言Client端)
Redis:安装.配置.操作和简单代码实例(C语言Client端) - hj19870806的专栏 - 博客频道 - CSDN.NET Redis:安装.配置.操作和简单代码实例(C语言Client端 ...
- JAVA第十周《网络编程》学习内容总结
JAVA第十周<网络编程>学习内容总结 学习内容总结 1.初听到网络编程四个字可能会觉得很困难,实际上网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据,把数据发送到指定的位置, ...
- IT软件人员的技术学习内容(写给技术迷茫中的你) - 项目管理系列文章
前面笔者曾经写过一篇关于IT从业者的职业道路文章(见笔者文:IT从业者的职业道路(从程序员到部门经理) - 项目管理系列文章).然后有读者提建议说写写技术方面的路线,所以就有了本文.本文从初学者到思想 ...
- linux epoll机制对TCP 客户端和服务端的监听C代码通用框架实现
1 TCP简介 tcp是一种基于流的应用层协议,其“可靠的数据传输”实现的原理就是,“拥塞控制”的滑动窗口机制,该机制包含的算法主要有“慢启动”,“拥塞避免”,“快速重传”. 2 TCP socket ...
随机推荐
- FCoE简单介绍
目录 FCoE 使用前提 FCoE FCoE是一种融合网络技术,其目的是将FC帧封装到以太网帧中,实现以太网链路与光纤链路通信的功能. SAN一般指存储区域网络,FC SAN 有光纤组网,IP SAN ...
- [POI2011]MET-Meteors 解题报告
语言系统紊乱了 QAQ 这道题感觉不是很难鸭 qwq. 先只考虑一个国家,怎么做?很显然,就直接二分一下就行了.判定答案可以维护一个差分数组,然后最后对它做一个前缀和,再求一下这个国家的流行数量就好了 ...
- MySQL数据类型补充
数据类型 整数数据类型 特殊说明: 对于整数类型,MySQL还支持在类型名称后面加小括号(M),而小括号中的M表示显示宽度,M的取值范围是(0, 255).int(M)这个M在字段的属性中指定了u ...
- 如何免费获取高清动图并将其插入到Markdown中
一.发现问题 我在做excel笔记的时候,想要动态展示操作excel的过程,由于我平时的笔记都是使用markdown记录,所以要在md文件中插入动图. 二.解决问题 细化问题 1.如何将动图插入到md ...
- array copy() 的简单使用
源码: public static native void arraycopy(Object src, int srcPos, Object dest, int destPos,int length) ...
- Linux中使用Makefile来运行QuestaSim
环境:Win7x64,VMware15.0,centOS7.0,QuestaSim10.7c 假设已经编辑好了一个全加器还有运行这个DUT的testbech,代码如下: 点击查看代码 // filen ...
- 解决CORS跨域问题
首先创建一个实现Filter的cors过滤器 import lombok.extern.slf4j.Slf4j; import org.springframework.context.Applicat ...
- 1839:【05NOIP提高组】谁拿了最多奖学金
1839:[05NOIP提高组]谁拿了最多奖学金 时间限制: 1000 ms 内存限制: 65536 KB提交数: 9569 通过数: 4431 [题目描述] 某校的惯例是在每 ...
- mysql 5.7 gtid 主从复制
GTID中slave端的binlog是必须开启的,目的是记录执行过的GTID 主库#开启gtidlog-bin=mysql-binexpire_logs_days = 5binlog_format=r ...
- 均值、中值、高斯、non-local means算法详解
文章仅为个人理解,如有不妥之处欢迎指正. 写几个常见的图像去噪滤波器. 1.均值滤波器 均值滤波器是最简单的图像平滑滤波器,其3*3的模板为 1 9 [ 1 1 1 1 1 1 1 1 1 ] \fr ...