您现在的位置是:群英 > 开发技术 > 移动开发
Android怎样做展现历史搜索记录的功能
Admin发表于 2022-05-17 11:46:351443 次浏览
这篇文章主要给大家介绍“Android怎样做展现历史搜索记录的功能”的相关知识,下文通过实际案例向大家展示操作过程,内容简单清晰,易于学习,有这方面学习需要的朋友可以参考,希望这篇“Android怎样做展现历史搜索记录的功能”文章能对大家有所帮助。



本文实例为大家分享了android实现历史搜索记录的具体代码,供大家参考,具体内容如下

在app 的 build.gradle下添加依赖

dependencies {
 
    .....
 
    api 'com.hyman:flowlayout-lib:1.1.2'
}

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"
    android:orientation="vertical"
    tools:context=".mainactivity">
 
    <edittext
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:hint="请输入你要搜索的内容"
        android:layout_height="wrap_content" />
 
    <button
        android:id="@+id/sure"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="确定"/>
 
    <button
        android:id="@+id/clear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="清空"/>
 
    <com.zhy.view.flowlayout.tagflowlayout
        android:id="@+id/flow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
 
</linearlayout>

java

public class mainactivity extends appcompatactivity {
 
    private button sure,clear;
    private tagflowlayout flow;
    private edittext edit;
    private list<string> list;
    private textview tv;
    private layoutinflater from;
 
    private handler handler=new handler(){
        @override
        public void handlemessage(message msg) {
            super.handlemessage(msg);
            flow.setadapter(new tagadapter<string>(list) {
                @override
                public view getview(flowlayout parent, int position, string o) {
 
                    tv= (textview) from.inflate(r.layout.item,flow,false);
                    tv.settext(o);
                    return tv;
                }
            });
        }
    };
 
 
    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);
 
        sure=findviewbyid(r.id.sure);
        clear=findviewbyid(r.id.clear);
        flow= findviewbyid(r.id.flow);
        edit= findviewbyid(r.id.edit);
 
        list=new arraylist<>();
        from = layoutinflater.from(this);
 
        //确定
        sure.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view v) {
                string trim = edit.gettext().tostring().trim();
                list.add(trim);
                handler.sendemptymessagedelayed(1,0);
            }
        });
 
        //清空
        clear.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view v) {
                list.clear();
                handler.sendemptymessagedelayed(1,0);
            }
        });
    }
}

item布局

<?xml version="1.0" encoding="utf-8"?>
<textview
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="#dddddd"/>

通过以上内容的阐述,相信大家对“Android怎样做展现历史搜索记录的功能”已经有了进一步的了解,更多相关的问题,欢迎关注群英网络或到群英官网咨询客服。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

相关信息推荐
2022-10-17 18:41:12 
摘要:方法:1、定义数组时给所有元素赋初值,例“int a[5]={1,2,3,4,5}”;2、给一部分元素赋值,例“int a[5]={1,2}”;3、定义时不指定数组长度,直接给所有元素赋初值,例“int a[]={1,2,3,4,5}”。
2022-05-27 18:02:29 
摘要:java正则表达式用法:1、使用Pattern类进行字符串的拆分,使用的方法是【String[] split(CharSequence input)】;2、使用Matcher类进行字符串的验证和替换。
2022-01-14 18:36:23 
摘要:PHP中如何判断元素是否包含在数组中?这里给大家分享两个判断方法,分别是使用in_array()函数和使用array_search()函数,这两个函数的使用并不难,实现代码如下,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧!
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部