EditText和数据库结合使用,类似淘宝搜索功能及历史记录

今天,是一个值得纪念的日子,是我小菜菜,手写的第一份博客,也不知道写点什么,那么,就写一个前段日子在公司新改的需求吧,其实挺简单的,我们的需求的呢,是这样的,搜索的内容呢 只需要在下面展示5个就可以,然后历史记录下面还要有一个搜索推荐,数据保存到本地 那么 我使用的是数据库,so,那么 我来看看 我是如何实现的,当然,方法大家可能都见过,只是一时之间想不起来而已了,好吧 ,说的太多了,我们来看代码
先看:
布局XML
搜索界面主布局

主布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    tools:context=".activity.game.SearchGameActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="38dp"
        android:background="@color/wankr_stand_title"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="29dp"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/bg_white">


            <EditText
                android:id="@+id/search_edit_text"
                android:layout_width="match_parent"
                android:layout_height="29dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:background="@null"
                android:imeOptions="actionSearch"
                android:singleLine="true"
                android:textColor="#333333"
                android:textCursorDrawable="@null"
                android:textSize="13sp" />

            <ImageView
                android:id="@+id/search_iv_cancel"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="8dp"
                android:src="@drawable/search_cancle" />

        </RelativeLayout>

        <TextView
            android:id="@+id/search_tv_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="10dp"
            android:layout_weight="0"
            android:text="取消"
            android:textColor="#ffffff"
            android:textSize="12sp" />


    </LinearLayout>


    <ListView
        android:id="@+id/search_result_game"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@null"
        android:listSelector="#00000000"
        android:scrollbars="none">

    </ListView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/game_disable"
        android:visibility="gone">

        <ImageView
            android:id="@+id/iv_nodata"
            android:layout_width="120dp"
            android:layout_height="200dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="65dp"
            android:background="@color/game_disable"
            android:src="@drawable/v1_2_img_data_empty"
            android:visibility="gone" />

        <ImageView
            android:id="@+id/img_txt_no_data"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv_nodata"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="30dp"
            android:src="@drawable/v1_2_txt_data_empty"
            android:visibility="gone" />
    </RelativeLayout>


</LinearLayout>

下面我们来写历史记录的布局,headview:
headview

headview的布局,历史记录和搜索推荐是一起的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/his_lin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/histotry_search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="22dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="13dp"
                android:layout_weight="9"
                android:text="历史记录"
                android:textColor="#999999"
                android:textSize="15sp" />

            <ImageView
                android:id="@+id/pic_deleate"
                android:layout_width="40dp"
                android:layout_height="39dp"
                android:padding="12dp"
                android:src="@drawable/delate" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="21dp"
            android:orientation="horizontal">

            <TextView

                
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值