ListView和SQLite数据库案例--商品展示

这篇博客展示了如何在Android应用中结合ListView和SQLite数据库实现商品管理功能。包括商品的增、删、改、查操作,通过XML布局文件定义界面,使用自定义适配器显示ListView数据,同时详细讲解了数据库的创建、操作方法。
摘要由CSDN通过智能技术生成

在商品展示案例中我们可以在界面中对商品进行增、删、改、查。要实现这些功能需要使用ListView 和 SQLine数据库

1、运行效果图

2、实现过程   

activity_main.xml,如图

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="cn.edu.bzu.test02.MainActivity">
    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
        <EditText android:id="@+id/nameET" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:hint="商品名称"/>
        <EditText android:id="@+id/balanceET" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:hint="金额"/>
        <ImageView android:id="@+id/add" android:layout_width="wrap_content" android:layout_height="25dp" android:layout_weight="1" android:onClick="add" android:src="@drawable/add"/>
    </LinearLayout>
    <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="30dp">
    </ListView>
</RelativeLayout>

ListView布局文件:item.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="wrap_content" android:orientation="horizontal">

    <TextView android:id="@+id/idTV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="13" android:textColor="#000000" android:textSize="20sp"/>

    <TextView

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值