一般在外卖的选单中常常会用到ListView的多选,大家可以改进后加入自己的项目中。下面看一下代码:
一、代码
1.main.xml:(由一个ListView和一个Button组成)
<?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="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/drink_list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
<Button
android:id="@+id/btn_commit"
android:layout_width="match_parent"
android:layout_height="58dp"
android:text="确定" />
</LinearLayout>
2.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="match_parent"
android:background="#ffffff"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="true" />
<ImageView
android:id="@+id/food_imager"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ffffff" />
<TextView
android:id="@+id/food_name"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="咖啡&#