android 利用数据库实现历史搜索记录功能

最近在一个项目中使用到了搜索功能,特来此记录一下

本篇博文需要用到的知识点:

1.RecyclerView的简单操作

2.本地数据库的简单操作

3.ScrollView与RecyclerView的滑动冲突解决

废话不多说,先上效果图


先看看工程界面截图


其中HistorySearchAdapter是历史记录的适配器,HistorySearchUtil是本地数据库的管理工具类

1.

<?xml version="1.0" encoding="utf-8"?>
<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="zzx.historysearch.MainActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        android:paddingTop="4dp"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:paddingBottom="4dp">

        <EditText
            android:id="@+id/search_edit"
            android:layout_width="0dp"
            android:layout_weight="6"
            android:layout_height="wrap_content"
            android:hint="搜索"
            android:textColor="#333333"
            android:textColorHint="#dddddd"
            android:textSize="15sp"/>
        <TextView
            android:id="@+id/search_tv"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="搜索"
            android:textSize="15sp"
            android:textColor="#ffffff"
            android:layout_centerVertical="true"
            android:layout_marginLeft="6dp"/>

    </LinearLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="历史纪录"
                android:textColor="#dddddd"
                android:textSize="13sp"
                android:paddingTop="8dp"
                android:paddingLef
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值