sqlife查询报错及关键字加粗的实现示例简单记录如下:
/** * 搜索知识点 * @param query * @return */ public List<KnowledgePoint> searchKnowledgePoints(String query , String subjectId) { if(query == null){ return null; } KnowledgePoint kp = null; List<KnowledgePoint> kpList = new ArrayList<KnowledgePoint>(); /** * 防止用户输入'号引起崩溃 */ query = query.replace("'", "''"); String sql = "select * from " + TABLE_NAME_KNOWLEDGE_POINT + " where subject_id=? and point_name like ?"; SQLiteDatabase db = this.getReadableDatabase(); String[] argv = new String[] {subjectId , "%" + query + "%"}; Cursor cursor = db.rawQuery(sql, argv); while (cursor.moveToNext()) { kp = new KnowledgePoint(); kp.setSubjectId(cursor.getString(0)); kp.setKid(cursor.getString(2)); kp.setParentId(cursor.getString(3)); /** * 搜索关键字变粗 */ kp.setName(cursor.getString(4).replace(query , "<strong>"+query+"</strong>")); kp.setIcon(cursor.getInt(5)); kpList.add(kp); } cursor.close(); this.closeDB(); return kpList; }
?