安卓开发(二)ListView显示菜单,SQLite存储和ListView显示

本次的安卓应用介绍的是listview和安卓SQLite数据库的应用,主要功能是:
1.创建数据库,并可以向数据库中添加菜单。菜单的条目有:编号、图片、名称、价格、简介。

2.读取数据中的菜单,并在自己设计的ListView里面显示对应条目。

我采用的是SimpAdapter.具体代码如下:

布局文件:

main.xml

<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="5dp"
    tools:context="${relativePackage}.${activityClass}" >
  <LinearLayout 
      android:id="@+id/addll"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal">
    <Button 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="查看菜单" 
        android:layout_weight="1"
        android:onClick="chakan"
        android:textColor="#000000"
        android:textSize="10sp"/>
    <Button 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="清空菜单" 
        android:layout_weight="1"
        android:onClick="shanchu"
        android:textColor="#000000"
        android:textSize="10sp"/>
    </LinearLayout>
    <ListView
        android:id="@+id/lvi"
        android:layout_below="@id/addll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        </ListView>
</LinearLayout>

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/id"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值