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. Cesium用wsad进行场景漫游(九)

    2023-01-14 先看效果,wsadqe控制方向升降,鼠标拖动屏幕也可以控制方向 整理下思路: 1. 使用movement变量控制是否进行漫游 2.1 进行漫游则先将enableRotate等全部 ...

  2. 如何让别人pip install自己写的库?

    一. 构建项目目录结构 结构如图所示: 文件介绍:LICENSE和README.md在git建仓库时选上,克隆下来就会有,license最好选择MIT的.sort.py文件里随便写个方法用于直接调用: ...

  3. docker-compose部署rocketmq

    docker-compose安装: 1.从github上下载docker-compose二进制文件安装 Ubuntu下载docker-compose文件 sudo curl -L https://gi ...

  4. Study for Go ! Chapter two - Expression

    Study for Go ! Chapter two - Expression 1. Keyword Golang仅有 25 个保留关键字,体现了 golang 语法规则的简洁性 保留关键字不能用作常 ...

  5. centos7 部署 loonflow

    a workflow engine base on django 基于django的工作流引擎系统(通过http接口调用,可以作为企业内部统一的工作流引擎,提供诸如权限申请.资源申请.发布申请.请假. ...

  6. the default discovery settings are unsuitable for production use at least one of...的解决办法

    解决办法 elasticsearch.yml加上 discovery.type: single-node

  7. K8s存储之Volume、PV、PVC、SC

    Volume Volume(存储卷)是Pod中能够被多个容器访问的共享目录.Kubernetes的Volume概念.用途和目的与Docker的Volume比较类似,但两者不能等价.首先,Kuberne ...

  8. HttpClient 提交 JSON数据

    常见数据格式 application/x-www-form-urlencoded 这也是最常见的 POST 提交数据的方式,一般是用来提交表单. multipart/form-data 上传文件时通常 ...

  9. springmvc 能进入Controller,但是前端页面还是404

    问题现象: 1.Controller里面的方法上已经加了注解 @ResponseBody 2.能进入controller的方法里面: 3.前端返回状态码 404: 4.控制台没有异常信息: 问题原因: ...

  10. pycharm过期解决方案

    如果你的pycharm老是过期,你可以直接下载最新版本的pycharm,然后加入一个网站获取激活码即可 http://idea.medeming.com/jets/