本次的安卓应用介绍的是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"