Android 本地历史记录、及产品标签(支持单选、多选)实现(附源码)(使用鸿洋大神的FlowLayout开源库)

本文介绍了如何使用鸿洋大神的FlowLayout开源库实现Android应用中的本地历史记录功能和产品标签功能,包括从SharedPreferences中读写历史记录、限制记录数量、防止重复,以及设置单选、多选标签。详细讲解了各个功能的实现步骤,并提供了项目源码下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        最近的项目需要做本地历史记录功能,以前写的有些过时了,就在网上查了查较好的开源库、实现方式等。最终选择了鸿洋大神的FlowLayout流式布局,再搭配SharedPreferencesUtil工具类来实现本地历史记录功能。同时FlowLayout开源库还非常适合实现产品标签(支持单选、多选)功能,所以在Demo中也有具体的使用,研究研究总是没错的。

        开源库的下载、导入等操作就不再废话了,直接开始项目演示。

        注:文章末尾附项目源码下载地址及FlowLayout开源库地址

 

      效果展示

        主要功能:FlowLayout的使用、从SP中读取历史记录、将历史记录写入到SP中、历史记录最大数量限制、历史记录不可重复、最新查询的在最前边、清楚历史记录;FlowLayout预先设置选中、设置最大选中数、设置标签点击和选中监听、获取选中的标签、通过selecter完成标签选择的切换等。方便演示加入了测试数据。

          

      本地历史记录的实现

        1.页面布局:主要是在布局文件中使用TagFlowLayout实现流失布局,并通过自定义属性(zhy:max_select="0")规定标签的最大可选数。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:zhy="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eeeeee"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@mipmap/titlebar_bg">

        <RelativeLayout
            android:id="@+id/rl"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@null">

            <TextView
                android:id="@+id/tv_titlebar_center"
                android:layout_width="200dp"
                android:layout_height="match_parent"
                android:layout_centerHorizontal="true"
                android:ellipsize="end"
                android:gravity="center"
                android:maxLength="18"
                android:singleLine="true"
                android:text="商品查询"
                android:textColor="@color/themeTextColor"
                android:textSize="@dimen/themeTextSize" />

            <ImageView
                android:id="@+id/iv_titlebar_left"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:background="@null"
                android:padding="14dp"
                android:src="@mipmap/titlebar_back" />
        </RelativeLayout>

        <RelativeLayout
        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值