Android - Ormlite query to find a string
I am working on an application where I want to search for a row that matches a row in a table, I wrote the following code,
public ArrayList<LearningListDTO> getSearchLearningList(String searchString) {
ArrayList<LearningListDTO> learningListDTO = null;
QueryBuilder<LearningListDTO, Integer> contentByTypeQB = null;
PreparedQuery<LearningListDTO> preparedQuery = null;
try {
contentByTypeQB = getLearningDao().queryBuilder();
contentByTypeQB.orderByRaw("name ASC");
contentByTypeQB.where().like("name", "%" + searchString + "%");
Log.v("",
"Query Executed: "
+ contentByTypeQB.prepareStatementString());
preparedQuery = contentByTypeQB.prepare();
try {
learningListDTO = (ArrayList<LearningListDTO>) getLearningDao().query(
preparedQuery);
} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (java.sql.SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return learningListDTO;
}
In fact, I want the query to be something like: "If I type B, then it must first display the lines that start with B and then the lines that contain" B "(although it does start with A)"
Is this a way to do this?
Thanks in advance.:)
+3
source to share
No one has answered this question yet
Check out similar questions: