10
我更改Android軟鍵盤顯示搜索圖標,而不是輸入圖標。我的問題是:我怎麼能檢測到用戶點擊該搜索按鈕?檢測鍵盤搜索按鈕
我更改Android軟鍵盤顯示搜索圖標,而不是輸入圖標。我的問題是:我怎麼能檢測到用戶點擊該搜索按鈕?檢測鍵盤搜索按鈕
在edittext中,您可能使用了輸入法選項進行搜索。
<EditText
android:imeOptions="actionSearch"
android:inputType="text"/>
現在使用上的EditText編輯監聽器來處理搜索事件,如下圖所示:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// Your piece of code on keyboard search click
return true;
}
return false;
}
});
您可以使用OnQuerySubmit
聽者獲得鍵盤搜索按鈕單擊事件。
這裏是如何,
searchView.setOnQueryTextListener(queryTextListener);
SearchView.OnQueryTextListener queryTextListener
= new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
showLog("searchClickListener onQueryTextSubmit");
getPhotos(searchView.getQuery().toString());
return true;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
};
我的代碼不會用這種方法運行!它不適用於我 – Fcoder 2012-03-30 18:54:02
分享您的代碼.. – 2012-03-30 18:54:56
「它不工作」從來沒有幫助過任何人。具體是最棒的! – f2lollpll 2012-03-30 21:28:02