android SearchView有两个方法:setOnQueryTextFocusChangeListener和setOnFocusChangeListener。它们可以互换吗?他们之间有什么区别?
答案 0 :(得分:1)
1" setOnFocusChangeListener" (继承自android.view.View)是整个视图 2" setOnQueryTextFocusChangeListener"仅适用于AutoCompleteTextView。
请参阅SearchView的代码:
public void setOnQueryTextFocusChangeListener(OnFocusChangeListener listener) {
mOnQueryTextFocusChangeListener = listener;
}
******
mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
******
mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (mOnQueryTextFocusChangeListener != null) {
mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus);
}
}
});