开发一个购物车,需要将购物车中的商品以列表的形式展示,并且还需要对购物车中的商品进行增删改查操作。要实现这些功能就需要使用 ListView 和 SQLite 数据库
运行效果图
添加数据
删除名称为123的商品
修改数据——给shangpin金额增加2
单击maojin条目时弹出Toast显示相应信息
案例分析
1、使用 SQLite 完成 CRUD 操作
2、ListView 控件的使用
3、运用Adapter 桥梁的作用
1、相应布局文件:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="8dp"
tools:context="cn.edu.bzu.product.MainActivity">
<LinearLayout
android:id="@+id/addLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/nameET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="商品名称"
android:inputType="textPersonName"/>
<EditText
android:id="@+id/balanceET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="金额"
android:inputType="number"/>
<ImageView
android:onClick="add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=