0
我在我的應用程序中實現了關鍵字搜索,但當我點擊軟鍵盤上的搜索(即問號)鍵時,我沒有得到任何回調。我已經將TextWatcher添加到了我的EditText中,但當我點擊搜索時它不會被調用。 Activity.onKeyUp()也不會被調用。我如何知道用戶何時點擊搜索鍵?
有什麼方法可以知道用戶何時點擊軟鍵盤上的搜索鍵?
在此先感謝...
我在我的應用程序中實現了關鍵字搜索,但當我點擊軟鍵盤上的搜索(即問號)鍵時,我沒有得到任何回調。我已經將TextWatcher添加到了我的EditText中,但當我點擊搜索時它不會被調用。 Activity.onKeyUp()也不會被調用。我如何知道用戶何時點擊搜索鍵?
有什麼方法可以知道用戶何時點擊軟鍵盤上的搜索鍵?
在此先感謝...
使用搜索查看這樣
SearchView sv=(SearchView)findViewByid(R.id.sv);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
//here is when clicking the search button in keyboard
}
@Override
public boolean onQueryTextChange(String s) {
//here is when the text change
return false;
}
});
編輯我已經找到了客場做到這一點:
在XML<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:imeOptions="actionSearch"
android:inputType="text"/>
onCreate方法中的
((EditText)findViewById(R.id.editText)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Toast.makeText(MainActivity.this,"searching",Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
這就是我沒有使用搜索查看所有
。我在操作欄中使用我自己的客戶EditText。有另一種方法嗎? –
非常感謝您的更新。它調用onEditorAction(),但我無法關閉鍵盤。由於它認爲用戶仍在鍵入,因此可能無法關閉鍵盤來響應按鍵。 : -/ –
爲什麼後退按鈕不起作用? –