SqlLite可以提供应用持久化数据,可储存大量的数据(相比于内部存储)
案例:
效果图

创建布局文件
<?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:background="@android:color/darker_gray"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="130dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名"
android:textSize="18sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_name"
android:hint="请输入姓名"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电话"
android:textSize="18sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_phone"
android:hint="请输入手机号码"

本文介绍了如何在Android中使用SqlLite数据库进行电话簿的增删查改操作。通过创建布局文件和Activity逻辑,详细阐述了初始化控件、获取数据、创建SQLiteOpenHelper子类、操作数据库、封装ContentValues以及执行SQL语句的过程。强调了操作结束后关闭数据库对象以防止数据泄露的重要性。
最低0.47元/天 解锁文章
4887

被折叠的 条评论
为什么被折叠?



