simple search library support T9
- Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
- set your entity as a T9 searchable entity, set parameter as searchable parameter
@T9SortableEntity
public class ContactsEntity {
@T9SearchKey // at least one search key require
private long key;
@T9Searchable(PinyinType = PinyinType.ALL)
private String name;
@T9Searchable
private String phone;
}
- init SearchDataCenter in your create
//get system phone contacts in demo, you can get your custom data list here.
ContactsManager.getInstance().initData(getContentResolver());
List<ContactsEntity> contactsEntityList = ContactsManager.getInstance().getContactsList();
//set List<Object> to SearchDataCenter data source
SearchDataCenter.getInstance().initSearchData(contactsEntityList);
SearchDataCenter.getInstance().init(this, new SearchDataCenter.OnSearchCompleteListener() {
@Override
public void onComplete(List<SearchableEntity> list) {
//search result callback
}
});
- destroy SearchDataCenter in your destroy
@Override
protected void onDestroy() {
super.onDestroy();
SearchDataCenter.getInstance().destroy();
}