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. 利用canvas+js完成滑块验证码中canvas部分思路

    1. 最终效果 2.滑块验证码思路 大概思路:设置两个画布,一个为显示图像的canvas画布,一个为拼图的block画布,block画布拼图内容从图像画布中的一部分裁剪得到(使用clip()),通过绑 ...

  2. async异步编程屏蔽凡人

    为提高效率与增加逼格,墙裂建议引入async异步编程,这不比基于threading的线程.基于multiprocessing的进程香?这些大家伙太重量级了,代码又啰里啰唆的一点也不pythonic,只 ...

  3. 跳板攻击之:NPS代理转发

    跳板攻击之:NPS代理转发 目录 跳板攻击之:NPS代理转发 1 NPS介绍 2 NPS特点 3 实验环境 3.1 实验准备 3.2 实验拓扑 3.3 NPS配置 3.3.1 conf/nps.con ...

  4. 配置 Vite 自动导入 ElementPlus 组件、函数、Icons、样式

    使用 Vite 的自动导入的前提是项目是 TS 项目,JS 项目使用 Vite 自动导入不生效.安装以下 5 个包到 devDependencies: cnpm i -D unplugin-icons ...

  5. Qt-FFmpeg开发-视频播放【软解码 + OpenGL显示RGB图像】(3)

    Qt-FFmpeg开发-视频播放[软解码 + OpenGL显示RGB图像] 目录 Qt-FFmpeg开发-视频播放[软解码 + OpenGL显示RGB图像] 1.概述 2.实现效果 3.FFmpeg软 ...

  6. LeetCode-798 得分最高的最小论调 及差分和前缀和的学习

    来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/smallest-rotation-with-highest-score 题目描述 给你一个数组  ...

  7. 这个博客几乎包括了Makefile中的所有 $ 符号解释

    来源:https://blog.csdn.net/dlf1769/article/details/78997967 Makefile中的$@, $^, $< , $?, $%, $+, $* h ...

  8. MySQL 修改字段子表中的顺序

    修改字段排列位置 ALTER TABLE 表名 MODIFY 字段名1 数据类型 FIRST|AFTER 字段名2 参数说明 FIRST,可选参数 将字段1,修改为表的第一个字段. AFTER 字段名 ...

  9. IDEA激活 重置试用30天

    转载于 https://www.cnblogs.com/renlywen/p/14216325.html jetbrains-agent已经停止,现在又出现了新的激活方式,重置试用时间,以下为操作步骤 ...

  10. 【CDH】cdh搭建遇到的坑和解决过程

    本人安装CDH时,使用的是在线安装方式,就是yum install XXX XXX XXX这种.所以安装目录都是默认的目录. Linxu:centos 7 一,启动cloudera-scm-agent ...