在商品展示案例中我们可以在界面中对商品进行增、删、改、查。要实现这些功能需要使用ListView 和 SQLine数据库。
1、运行效果图
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