Android实战简易教程-第四十七枪(ListView多选-实现点餐系统)

这篇博客介绍了如何在Android项目中使用ListView实现多选功能,以创建一个简单的点餐系统。通过代码示例和运行实例,展示了如何构建由ListView和Button组成的界面。
摘要由CSDN通过智能技术生成

一般在外卖的选单中常常会用到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="咖啡&#
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值