I would like to implement T9 search like android native dialer or TrueCaller dialer. What I have achieved till now is:-
Convert keystrokes to string patterns like if I press 2 on dialer it would gives me - "abc" "ac" "ca" and so on
Now I made a query
String selection = Utility.getSelectionLikeWithIn(mmemonics);
Cursor query = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, null);'
public static String getSelectionLikeWithIn(List mmemonics) {
String selection = "";
for (int i = 0; i < mmemonics.size(); i++) {
selection = selection + " display_name LIKE '";
selection = selection + mmemonics.get(i);
if (i == mmemonics.size() - 1){
selection = selection + "%'";
}else {
selection = selection + "%' OR";
}
}
return selection;
}'
above method convert Arraylist of string to where clause
where display_name Like 'ab%' OR display_name LIKE 'abc%' and so on......
well this give me the inefficient result and app crash due to complex query.....
Please suggest me how can I perform a query to match like my keystroke or os their any other way in ContactsProvider to perform such smart search