标签:
public void openSearch(){ search = (SearchBox) findViewById(R.id.searchbox); search.enableVoiceRecognition(this); search.revealFromMenuItem(R.id.iv_search, this); //Showing from a MenuItem 点击一个menu Item,在这里显示出来 for (int x = 0; x < 10; x++) { SearchResult option = new SearchResult("Result " + Integer.toString(x), getResources().getDrawable(R.mipmap.ic_launcher)); search.addSearchable(option); } search.setSearchListener(new SearchBox.SearchListener() { //刚点击搜索按钮调用 @Override public void onSearchOpened() { display("onSearchOpened"); } //点击推出按钮调用 @Override public void onSearchClosed() { display("onSearchClosed被调用了"); closeSearch(); } //监听输入框,一旦变化就调用 @Override public void onSearchTermChanged(String term) { display("onSearchTermChanged被调用了"); } @Override public void onSearch(String searchTerm) { // display(searchTerm + " Searched"); display("onSearch被调用了"); } //点击显示内容的,被调用 @Override public void onResultClick(SearchResult result) { display("onResultClick被调用了"); } //搜索结束后吧。 没被调用过。 @Override public void onSearchCleared() { display("onSearchCleared被调用了"); } }); }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1234 && resultCode == RESULT_OK) {
ArrayList<String> matches = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
search.populateEditText(matches.get(0));
}
super.onActivityResult(requestCode, resultCode, data);
}
//隐藏起来
protected void closeSearch() {
search.hideCircularly(this);
}
标签:
原文地址:http://www.cnblogs.com/zrui513/p/4965045.html