I am building a contact app which is using SQL database. I have a search function for user. User can search by key in an alphabet and then the list will show from the alphabet to z. For example, if user key is t, the list will show contact names starting from t to z. I create a table whose name is contactstable and store contact name in sname. Below is my code. However, it fails to search. Can anyone please help me?
public void search(View view) {
cursor = db.rawQuery("SELECT _id, sname FROM contactstable WHERE sname LIKE ? ORDER BY sname COLLATE NOCASE",
new String[]{"["+searchText.getText().toString() + "-z]%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.employee_list_item,
cursor,
new String[] {"sname"},
new int[] {R.id.firstName});
setListAdapter(adapter);
}
I am using the same method as the answer of below post and solve my problem.
How to use [charlist] Wildcard in android sql search