实验:Android案例——商品展示

该博客详细记录了一次Android实验,主要介绍了如何实现商品展示功能。从实验要求到运行截图,再到代码实现和关键知识点的解析,全面展示了Android UI设计与数据绑定的过程。同时,博主分享了在开发中遇到的问题及解决策略。
摘要由CSDN通过智能技术生成

一、实验要求

      开发一个购物车,需要将购物车中的商品以列表的形式展示,并且还需要对购物车中的商品进行增删改查操作。要实现这些功能就需要使用ListView和SQLite数据库。

二、运行效果图


三、训练目标

(1)、掌握SQLite存储方式
(2)、掌握如何使用SQLite完成CRUD操作

四、用到的class文件和布局文件


五、具体实现代码

(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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="bzu.edu.cn.lab7_4.MainActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="商品名称"
            android:id="@+id/EdName"
            />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="金额"
            android:id="@+id/EdBalance"
            />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/ic_input_add"
            android:id="@+id/IVAdd"
            android:onClick="addProduct"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/lv_product"/>
    </LinearLayout>

</LinearLayout>
(2࿰
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值