搜索添加数据库+清空历史记录
创建数据库
db = openOrCreateDatabase("db", MODE_PRIVATE, null);
创建表 db.execSQL("create table if not exists user(id integer primary key,name varchar(20))");
进入应用先查询数据库,有数据让他展示出来,没有自然是空的 Cursor cursor = db.rawQuery("select * from user", null); while (cursor.moveToNext()){String name = cursor.getString(cursor.getColumnIndex("name")); list.add(name); }
判断集合的长度,如果数据库里有数据,设置适配器
if (list.size()>0){stringArrayAdapter = new ArrayAdapter<>(Main3Activity.this, android.R.layout.simple_list_item_1, list); listView.setAdapter(stringArrayAdapter); listView.setOnItemClickListener(this); //有数据的话将下方的布局自己显示出来 linear.setVisibility(View.VISIBLE); }
点击搜索的方法
public void search(View view) {String s = edit_text.getText().toString(); if (s !=null){Intent intent = new Intent(Main3Activity.this,SearchActivity.class); intent.putExtra("str", s); startActivity(intent);
点击搜索的同时将输入框中的值获取到并存入到数据库中 db.execSQL("insert into user(name)values(?)",new String[]{s}); list.add(s); stringArrayAdapter.notifyDataSetChanged(); }}
点击清空的方法
public void clear(View view) {if (list.size()>0){db.execSQL("delete from user"); }AlertDialog.Builder builder = new AlertDialog.Builder(Main3Activity.this); builder.setTitle("确定清空历史搜索吗?"); builder.setNegativeButton("取消",null); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Override public void onClick(DialogInterface dialog, int which) {list.clear(); stringArrayAdapter.notifyDataSetChanged(); linear.setVisibility(View.INVISIBLE); }}); builder.create().show(); }
点击子条目直接搜索
String s = list.get(position); if (s !=null){Intent intent = new Intent(Main3Activity.this,SearchActivity.class); intent.putExtra("str", s); startActivity(intent); }
搜索添加数据库+清空历史记录相关推荐
- 基于uniapp缓存写的搜索历史记录,清空历史记录,点击历史记录直接搜索
先看页面效果 简介 输入值回车搜索,会把搜索值加入缓存中. 点击历史记录可直接搜索,点击"暂未搜索记录" 没有效果哦 清空记录就是清空缓存 使用的技术 1. uni.getStor ...
- android 搜索历史流布局,FlowLayout流式布局实现搜索清空历史记录
本文实例为大家分享了FlowLayout实现搜索清空历史记录的具体代码,供大家参考,具体内容如下 效果图:点击搜索框将搜索的历史在流式布局中展示出来,清空历史记录就会将历史清空,每次搜索后都存入sp中 ...
- FlowLayout流式布局实现搜索清空历史记录
效果图:点击搜索框将搜索的历史在流式布局中展示出来,清空历史记录就会将历史清空,每次搜索后都存入sp中,每次进入页面都先判断sp里是否有值并展示 首先需要导入一个module,下载地址:https:/ ...
- linux怎么清空历史记录,linux清空历史记录
前几天弄了个Linux服务器做网站,发现在不同终端登陆时,上下键都会出现一堆无用的命令,搜了一下解决方法,做个笔记. 在Linux中,每个用户目录下都有一个.bash_history文件用于保存历史命 ...
- Vue 历史记录的本地存储 清空历史记录
//Search-index.vue是父组件,引用Header.vue子组件 //Header.vue> <div class="search-main">< ...
- dedecms首页搜索 添加仿百度下拉框
1:找到uploads/templets/default/head.htm 2: 找到 <input name="q" type="text" clas ...
- 清空mysql注册表步骤_完全卸载MySQL 数据库清空MySql注册表
完全卸载MySQL 数据库--清空MySql注册表 完全卸载Mysql的步骤主要有以下4步: 1. 通过控制面板- 卸载程序--mysql 将其卸载掉. 2. 删除Mysql 安装文件目录下的Mysq ...
- 使用fuse.js_如何使用Fuse.js将搜索添加到React应用
使用fuse.js Search is a powerful way help people visiting your site find the content that's most impor ...
- 手机360浏览器怎么清空历史记录 手机360浏览器历史记录清空方法分享
任何一款浏览器产品在使用一段时间后都会出现历史记录,手机360浏览器自然也不能例外.而这些历史记录如果长期不清理的话,则导致手机越来越卡!那么,手机360浏览器怎么清空历史记录?不清楚具体操作的朋友, ...
最新文章
- PHP中过滤常用标签的正则表达式
- 独立式环境与宿主式环境————《标准C语言指南》读书笔记01
- wxHtml 示例:帮助浏览器
- 在nagios中使用nrpe自定义脚本
- Django源代码写DetailView与ListView
- java解析excel文件_1.3.1 python解析excel格式文件
- el-table跨页选中
- 任务记录:OEA 框架中的多类型树控件
- Spring MVC登录实例
- Fiddler笔记(4)浏览器抓包
- Oracle 临时表
- 存储数据使用数据库而不用EXCEL
- 041创建MDI程序
- 富文本 和 图片裁切
- 立创EDA---PCB
- 拼图游戏 java_Java实现拼图游戏
- 翻译-现代浏览器的架构与发展
- 阿里云服务器搭建视频
- esp32--无线控制灯
- Centos7 添加大于2T磁盘,使用GPT硬盘格式和XFS文件系统