Android中ListView和SQLite结合实例---待办事项应用

我们都知道,在安卓开发中,ListView是非常重要且常用的一个控件,而SQLite也以其轻量型特性被大家广泛使用,因此,这二者在一起必定会擦出不一样的火花。

 

今天就通过一个关于待办事项的小例子来加深对于他们的理解。

 

 

一、需求分析

说明:

 

u  应用分为三个界面:待办清单页面,详情内容页面,添加页面

u  代办清单页面展示所有的代办清单内容

u  点击页面清单中一项,例如洗衣服,跳转到详细内容页面

u  详细内容页面展示当前点击项的具体内容,点击返回按钮,返回代办清单页面

u  在代办清单页面点击添加按钮,跳转到添加页面

u  添加页面输入完成点击完成按钮,返回代办清单页面。点击完成时输入为空,提示请输入内容;点击返回时不保存当前页内容,返回待办清单页面

 

 

二、界面设计

     1、 先设计出三个界面,代码如下:

                (1)         代办清单页面:activity_main.xml

 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:gravity="center"
        android:text="代办清单"
        android:textSize="20dp"
        android:layout_gravity="center"
        android:background="@color/black"
        android:textColor="@color/white"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"/>
    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

    </ListView>
    <Button
        android:id="@+id/add"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:layout_gravity="center"
        android:text="+"
        android:textSize="30dp"
        android:textColor="#969696"
        android:layout_marginBottom="30dp"
        android:background="@drawable/btn_circle">
    </Button>

</LinearLayout>

               (2)    详情内容页面:detail_xml

 

 

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@color/black"
        android:layout_marginBottom="40dp">

        <Button
            android:id="@+id/back_detail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="返回"
            android:textSize="20dp"
            android:background="@null"
            android:layout_weight="1"
            android:textColor="@color/white">
        </Button>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="详细内容"
            android:textSize="20dp"
            android:gravity="center"
            android:layout_weight="1"
            android:textColor="@color/white">
        </TextView>
        <Button
            android:id="@+
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值