diff options
| author | Amith Yamasani <yamasani@google.com> | 2010-12-03 14:43:52 -0800 |
|---|---|---|
| committer | Amith Yamasani <yamasani@google.com> | 2010-12-03 15:21:07 -0800 |
| commit | 483854820945ae8b4e4512b696cce7da92deed20 (patch) | |
| tree | f2d4123cc5ac39cabd879dbfa1a44d3d9006abb4 /core/java/android/widget/SearchView.java | |
| parent | f870c28d76140f1a35089c281f78fcb3998ef618 (diff) | |
Added to SearchView : getQuery() and setOnSearchClickListener()
Bug: 3083393
Bug: 3172295
Diffstat (limited to 'core/java/android/widget/SearchView.java')
| -rw-r--r-- | core/java/android/widget/SearchView.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index b296b7734d83..b32bd42a8d9a 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -44,6 +44,7 @@ import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; @@ -76,6 +77,7 @@ public class SearchView extends LinearLayout { private OnCloseListener mOnCloseListener; private OnFocusChangeListener mOnQueryTextFocusChangeListener; private OnSuggestionSelectionListener mOnSuggestionListener; + private OnClickListener mOnSearchClickListener; private boolean mIconifiedByDefault; private boolean mIconified; @@ -301,6 +303,27 @@ public class SearchView extends LinearLayout { } /** + * Sets a listener to inform when the search button is pressed. This is only + * relevant when the text field is not visible by default. Calling #setIconified(false) + * can also cause this listener to be informed. + * + * @param listener the listener to inform when the search button is clicked or + * the text field is programmatically de-iconified. + */ + public void setOnSearchClickListener(OnClickListener listener) { + mOnSearchClickListener = listener; + } + + /** + * Returns the query string currently in the text field. + * + * @return the query string + */ + public CharSequence getQuery() { + return mQueryTextView.getText(); + } + + /** * Sets a query string in the text field and optionally submits the query as well. * * @param query the query string. This replaces any query text already present in the @@ -831,6 +854,9 @@ public class SearchView extends LinearLayout { mQueryTextView.requestFocus(); updateViewsVisibility(false); setImeVisibility(true); + if (mOnSearchClickListener != null) { + mOnSearchClickListener.onClick(this); + } } private void onVoiceClicked() { |
