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端代码编写的更多相关文章

  1. server端获得到client端的IP地址的格式

    使用telnet,ping或其他client连接server端时,server端获得的client端的ip地址取决于client端使用的时ipv4还是ipv6地址. 例: client IPv4地址: ...

  2. 搜集的一些RTMP项目,有Server端也有Client端

    查询一些RTMP的协议封装时找到了一些RTMP开源项目,在这里列举一下,以后有时间或是有兴趣可以参考一下: just very few of them. Red5 only contains a se ...

  3. 使用gRPC搭建Server端与Client端

    gRPC简介 gRPC是一种RPC框架技术,采用Protocal Buffers(协议缓存) 作为其接口定义的语言(就是Proto来写接口)和基础的消息交换格式. 在gRPC中,客户端应用程序可以直接 ...

  4. 基于Netty和SpringBoot实现一个轻量级RPC框架-Client端请求响应同步化处理

    前提 前置文章: <基于Netty和SpringBoot实现一个轻量级RPC框架-协议篇> <基于Netty和SpringBoot实现一个轻量级RPC框架-Server篇> & ...

  5. u-boot代码学习内容

    前言  u-boot代码庞大,不可能全部细读,只能有选择的读部分代码.在读代码之前,根据韦东山教材,关于代码学习内容和深度做以下预先划定. 一.Makefile.mkconfig.config.mk等 ...

  6. 从零开始学习Node.js例子四 多页面实现数学运算 续二(client端和server端)

    1.server端 支持数学运算的服务器,服务器的返回结果用json对象表示. math-server.js //通过监听3000端口使其作为Math Wizard的后台程序 var math = r ...

  7. Redis:安装、配置、操作和简单代码实例(C语言Client端)

    Redis:安装.配置.操作和简单代码实例(C语言Client端) - hj19870806的专栏 - 博客频道 - CSDN.NET Redis:安装.配置.操作和简单代码实例(C语言Client端 ...

  8. JAVA第十周《网络编程》学习内容总结

    JAVA第十周<网络编程>学习内容总结 学习内容总结 1.初听到网络编程四个字可能会觉得很困难,实际上网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据,把数据发送到指定的位置, ...

  9. IT软件人员的技术学习内容(写给技术迷茫中的你) - 项目管理系列文章

    前面笔者曾经写过一篇关于IT从业者的职业道路文章(见笔者文:IT从业者的职业道路(从程序员到部门经理) - 项目管理系列文章).然后有读者提建议说写写技术方面的路线,所以就有了本文.本文从初学者到思想 ...

  10. linux epoll机制对TCP 客户端和服务端的监听C代码通用框架实现

    1 TCP简介 tcp是一种基于流的应用层协议,其“可靠的数据传输”实现的原理就是,“拥塞控制”的滑动窗口机制,该机制包含的算法主要有“慢启动”,“拥塞避免”,“快速重传”. 2 TCP socket ...

随机推荐

  1. helm在k8s上部署Elasticsearch和Kibana

    前提 在win上安装docker desktop,没有网络限制,而且,打开kubernetes之后,很快就安装启动好了. 在win上安装scoop,有网络限制,需要访问github raw的文件内容, ...

  2. MySQL 中的锁有哪些类型,MySQL 中加锁的原则

    MySQL 中的锁理解 锁的类型 全局锁 缺点 适用范围 表级锁 表锁 元数据锁 意向锁 自增锁 行锁 Record Lock Gap Lock Next-Key Lock 插入意向锁 加锁的原则 1 ...

  3. 大道至简的架构设计思想之:封装(C系架构设计法,sishuok)

    一起来看看大道至简的一些基本设计思想,首先我们来看一下什么是封装. 封装:也叫做信息隐藏,或者数据访问保护.放到程序上来讲,就是隐藏类的属性,还有实现细节,仅对外公开一些接口.那么外部,就只能通过这个 ...

  4. wsl安装和使用

    1.安装wsl的版本 1.使用管理员身份打开powershell,执行 wsl --list --online 2.安装相应的版本 wsl --install -d Ubuntu-20.04 2.更改 ...

  5. C# 游戏雏形 人物地图双重移动

    1. 设计出发点 准备做一个旅游短视频,想实现一个小人或汽车在百度地图上按指定路线移动的效果,把之前自己写的代码拿出来,修改完成. 主要修改内容: (1)实现了人物地图双移动.即如果人物向屏幕中间移动 ...

  6. java如何将逗号分隔的字符串转成int或者long数组

    String str = "1,2,3";//先将他转化成int的数组如上述:欲将str 转成 数值型数组 利用 split 函数先以 ,分割 String str = " ...

  7. Windows清除DNS缓存

    第一步,刷新DNS WIN+R 输入cmd 再输入ipconfig/flushdns 第二步,恢复默认 输入netsh winsock reset 重启电脑.

  8. 【C学习笔记】day3-2 计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。

    #include <stdio.h> int main() { double sum = 0; double j = 1.0; for (int i = 1; i <= 100; i ...

  9. FastAPI中声明参数为必需的三种方式

    前提 有时候我们定义一些参数的时候,需要声明这个参数为必需,请求者必须传递该参数.FatstAPI中声明参数为必需的方式有三种,分别为:不设默认值.  "..." 和 " ...

  10. python 日志分割器 大文本处理

    import math i=0 filename='' write='' Rline = '' def writeFile(fileName,line): global filename global ...