Android-商品展示案例

1.创建程序

创建一个名为“商品展示”的应用程序,将包名修改为cn.edu.bzu。

2.用户交互界面

(1)“商品展示”程序对应的布局文件(activity_main.xml)

线性布局下包含一个水平显示的线性布局和一个ListView控件垂直显示;在水平显示的线性布局(LinearLayout)下建两个文本控件(EditText)“商品名称”、“金额”和一个显示图片控件。文本属性Android:inputType其中使用到了ImageView的属性Android:src来指定ImageView要显示的图片,但是只显示图片原图大小;如果使用Android:src属性,图片的大小会根据ImageView的大小进行拉伸。此外,ListView控件以列表的形式展示具体数据的内容,并且能够根据数据的长度自适应屏幕的显示。例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:layout_margin="8dp"
    tools:context="cn.edu.bzu.showproduct.MainActivity">
<LinearLayout
    android:id="@+id/addLL"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <EditText
        android:id="@+id/nameET"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="商品名称"
        android:inputType="textPersonName"/>
    <EditText
        android:id="@+id/balanceET"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="金额"
        android:inputType="number"/>
    <ImageView
        android:onClick="add"
        android:layout_width="30dp"
        android:layout_height="32dp"
        android:src="@drawable/input" />
</LinearLayout>
    <ListView
        android:id="@+id/accoutLV"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/addLL">
    </ListView>
</LinearLayout>

(2)ListView Item 布局(item.xml)

用到了ListView布局,故要编写一个ListView itemd的布局。在res/layout目录下建一个item.xml文件,该文件有三个TextView文本控件,分别用于显示数据库中的某条数据的id、商品名称、金额和三个ImageView图片控件用于增加、减少金额,删除数据。例:

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值