| — | — |
| SearchView.java | 搜索框所有功能的实现 |
| RecordSQLiteOpenHelper.java | 创建、管理数据库 & 版本控制 |
| EditText_Clear.java | 自定义EdiText,丰富了自定义样式 & 一键删除 |
| ICallBack.java | 点击搜索按键后的接口回调方法 |
| bCallBack.java | 点击返回按键后的接口回调方法 |
| SearchListView.java | 解决ListView & ScrollView的嵌套冲突 |
| search_layout.xml | 搜索框的布局 |
6. 功能详细设计
下面将给出详细的功能逻辑
6.1 关键字搜索
- 描述:根据用户输入的搜索字段进行结果搜索
- 原型图
注:关键字搜索功能是因人而异的,所以本源码仅留出接口供开发者实现,不作具体实现
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YEaskzAt-1651121171314)(https://user-gold-cdn.xitu.io/2018/1/29/1613f6d25f1d1440?imageView2/0/w/1280/h/960/ignore-error/1)]
- 源码分析
分析1:EditText_Clear.java
- 作用:自定义
EdiText
,与系统自带的EdiText
对比:多了左侧图片 & 右侧图片设置、一键清空EdiText
内容功能 - 具体代码如下:
public class EditText_Clear extends android.support.v7.widget.AppCompatEditText {
/**
- 步骤1:定义左侧搜索图标 & 一键删除图标
*/
private Drawable clearDrawable,searchDrawable;
public EditText_Clear(Context context) {
super(context);
init();
// 初始化该组件时,对EditText_Clear进行初始化 ->>步骤2
}
public EditText_Clear(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public EditText_Clear(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
/**
- 步骤2:初始化 图标资源
*/
private void init() {
clearDrawable = getResources().getDrawable(R.drawable.delete);
searchDrawable = getResources().getDrawable(R.drawable.search);
setCompoundDrawablesWithIntrinsicBounds(searchDrawable, null,
null, null);
// setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)介绍
// 作用:在EditText上、下、左、右设置图标(相当于android:drawableLeft=“” android:drawableRight=“”)
// 注1:setCompoundDrawablesWithIntrinsicBounds()传入的Drawable的宽高=固有宽高(自动通过getIntrinsicWidth()& getIntrinsicHeight()获取)
// 注2:若不想在某个地方显示,则设置为null
// 此处设置了左侧搜索图标
// 另外一个相似的方法:setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)介绍
// 与setCompoundDrawablesWithIntrinsicBounds()的区别:可设置图标大小
// 传入的Drawable对象必须已经setBounds(x,y,width,height),即必须设置过初始位置、宽和高等信息
// x:组件在容器X轴上的起点 y:组件在容器Y轴上的起点 width:组件的长度 height:组件的高度
}
/**
- 步骤3:通