FlowLayout流式布局实现搜索清空历史记录

该博客展示了如何在Android应用中实现搜索历史记录的流式布局展示,并提供了清空历史记录的功能。通过导入FlowLayout模块,设置XML布局,以及在MainActivity中处理搜索和清空操作,实现了搜索框中输入内容的存储和展示。点击搜索历史记录项可触发Toast提示。
摘要由CSDN通过智能技术生成

效果图:点击搜索框将搜索的历史在流式布局中展示出来,清空历史记录就会将历史清空,每次搜索后都存入sp中,每次进入页面都先判断sp里是否有值并展示


首先需要导入一个module,下载地址:https://github.com/zhangliyong114/FlowLayoutDemo

下载完这个工程后,需要将里面的flowlayout-lib导入到工程中,


导入工程的步骤:File - New - Import Module 选中这个flowlayout-lib

导入完成后,在项目的build.gradle中对导入的module进行依赖

[html] view plain copy
  1. compile project(':flowlayout-lib')  

activity_main.xml

[html] view plain copy
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:orientation="vertical"  
  7.     android:padding="16dp"  
  8.     tools:context="com.example.searchhistory.MainActivity">  
  9.   
  10.     <LinearLayout  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="wrap_content"  
  13.         android:gravity="center_vertical"  
  14.         android:orientation="horizontal">  
  15.   
  16.         <EditText  
  17.             android:id="@+id/edt"  
  18.             android:layout_width="0dp"  
  19.             android:layout_height="wrap_content"  
  20.             android:layout_weight="4" />  
  21.   
  22.         <Button  
  23.             android:id="@+id/btn"  
  24.             android:layout_width="0dp"  
  25.             android:layout_height="wrap_content"  
  26.             android:layout_weight="1"  
  27.             android:text="搜索" />  
  28.   
  29.         <Button  
  30.             android:id="@+id/clear"  
  31.             android:l
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值