android实现关键字搜索功能
2013-11-29 11:39
288 查看
//以关键字查找日记为例,主要是Sql语句
public ArrayList<DiaryBean> searchNotes(String keywords) {
if (keywords != null) {
ArrayList<DiaryBean> dList = new ArrayList<DiaryBean>();
//查询日记标题或内容含有关键字的记录
Cursor cusror = mDb.query(true, DATABASE_TABLE, new String[] { ROWID,
TITLE, BODY, CREATED, MOOD, WEATHER, COLOR, BACKGROUND, SIZE },
"TITLE like '%" + keywords + "%'"+" or BODY like '%" + keywords +"%'" , null, null, null, null, null);
while (cusror.moveToNext()) {
DiaryBean bean = new DiaryBean();
bean.setTitle(cusror.getString(cusror.getColumnIndex(TITLE)));
bean.setBody(cusror.getString(cusror.getColumnIndex(BODY)));
bean.setColor(cusror.getInt(cusror.getColumnIndex(COLOR)));
bean.setMood(cusror.getInt(cusror.getColumnIndex(MOOD)));
bean.setId(cusror.getInt(cusror.getColumnIndex(ROWID)));
bean.setTime(cusror.getString(cusror.getColumnIndex(CREATED)));
bean.setWeather(cusror.getInt(cusror.getColumnIndex(WEATHER)));
bean.setSize(cusror.getInt(cusror.getColumnIndex(SIZE)));
bean.setBackground(cusror.getInt(cusror
.getColumnIndex(BACKGROUND)));
dList.add(bean);
}
cusror.close();
return dList;
} else {
return null;
}
public ArrayList<DiaryBean> searchNotes(String keywords) {
if (keywords != null) {
ArrayList<DiaryBean> dList = new ArrayList<DiaryBean>();
//查询日记标题或内容含有关键字的记录
Cursor cusror = mDb.query(true, DATABASE_TABLE, new String[] { ROWID,
TITLE, BODY, CREATED, MOOD, WEATHER, COLOR, BACKGROUND, SIZE },
"TITLE like '%" + keywords + "%'"+" or BODY like '%" + keywords +"%'" , null, null, null, null, null);
while (cusror.moveToNext()) {
DiaryBean bean = new DiaryBean();
bean.setTitle(cusror.getString(cusror.getColumnIndex(TITLE)));
bean.setBody(cusror.getString(cusror.getColumnIndex(BODY)));
bean.setColor(cusror.getInt(cusror.getColumnIndex(COLOR)));
bean.setMood(cusror.getInt(cusror.getColumnIndex(MOOD)));
bean.setId(cusror.getInt(cusror.getColumnIndex(ROWID)));
bean.setTime(cusror.getString(cusror.getColumnIndex(CREATED)));
bean.setWeather(cusror.getInt(cusror.getColumnIndex(WEATHER)));
bean.setSize(cusror.getInt(cusror.getColumnIndex(SIZE)));
bean.setBackground(cusror.getInt(cusror
.getColumnIndex(BACKGROUND)));
dList.add(bean);
}
cusror.close();
return dList;
} else {
return null;
}
相关文章推荐
- Android中ListView字母排序,实现字母挤压效果以及右侧快速选中字母,搜索关键字功能
- Android之搜索功能的实现
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android ListView用EditText实现搜索功能
- Android中 实现输入框搜索,清楚历史记录的功能
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- ruby 操作字符串 实现关键字搜索功能
- Android 仿联系人列表 实现ListView的A-Z字母排序和过滤搜索功能,并挤压效果
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 利用AutoCompleteTextView实现模糊搜索功能,搜索结果自动提示,识别拼音首字母并转汉字提示
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- android代码实现搜索机身应用的功能
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 仿联系人列表 实现ListView的A-Z字母排序和过滤搜索功能
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- JavaScript简单实现关键字文本搜索高亮显示功能示例
- Android开发中搜索功能的实现
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android搜索功能实现