Obsolete
Status Update
Comments
cx...@gmail.com <cx...@gmail.com> #2
Seems it has already fixed in JellyBean.
Can you still reproduce it now?
Can you still reproduce it now?
g....@gmail.com <g....@gmail.com> #3
Same problem here. Both on ICS (4.0.4) and JellyBean (4.1.1).
g....@gmail.com <g....@gmail.com> #4
The same happens on 4.2.1
xp...@gmail.com <xp...@gmail.com> #5
Same on Galaxy Nexus 4.2.2
jo...@gmail.com <jo...@gmail.com> #6
same here on 4.2.2
ol...@gmail.com <ol...@gmail.com> #7
same on Nexus 7 4.3
re...@gmail.com <re...@gmail.com> #8
The listener is only called if:
1)The query text is empty
2)mIconifiedByDefault is true
3)The listener is not null
I don't really understand why.
This is the code in SearchView:
private void onCloseClicked() {
CharSequence text = mQueryTextView.getText();
if (TextUtils.isEmpty(text)) {
if (mIconifiedByDefault) {
// If the app doesn't override the close behavior
if (mOnCloseListener == null || !mOnCloseListener.onClose()) {
// hide the keyboard and remove focus
clearFocus();
// collapse the search field
updateViewsVisibility(true);
}
}
} else {
mQueryTextView.setText("");
mQueryTextView.requestFocus();
setImeVisibility(true);
}
}
1)The query text is empty
2)mIconifiedByDefault is true
3)The listener is not null
I don't really understand why.
This is the code in SearchView:
private void onCloseClicked() {
CharSequence text = mQueryTextView.getText();
if (TextUtils.isEmpty(text)) {
if (mIconifiedByDefault) {
// If the app doesn't override the close behavior
if (mOnCloseListener == null || !mOnCloseListener.onClose()) {
// hide the keyboard and remove focus
clearFocus();
// collapse the search field
updateViewsVisibility(true);
}
}
} else {
mQueryTextView.setText("");
mQueryTextView.requestFocus();
setImeVisibility(true);
}
}
be...@gmail.com <be...@gmail.com> #9
same here on 4.1.2
ke...@gmail.com <ke...@gmail.com> #10
same here on 4.4.4
he...@gmail.com <he...@gmail.com> #11
Here is a hack to get the same result even with android:iconifiedByDefault="false":
public static boolean setOnCloseListener (final SearchView search, final SearchView.OnCloseListener listener) {
try {
final int id = Resources.getSystem().getIdentifier("search_close_btn", "id", "android");
final ImageView close = (ImageView)search.findViewById(id);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view) {
if (listener == null || !listener.onClose()) {
search.setQuery("", false);
search.clearFocus();
}
}
});
return true;
}
catch (Exception e) {
return false;
}
}
public static boolean setOnCloseListener (final SearchView search, final SearchView.OnCloseListener listener) {
try {
final int id = Resources.getSystem().getIdentifier("search_close_btn", "id", "android");
final ImageView close = (ImageView)search.findViewById(id);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view) {
if (listener == null || !listener.onClose()) {
search.setQuery("", false);
search.clearFocus();
}
}
});
return true;
}
catch (Exception e) {
return false;
}
}
en...@google.com <en...@google.com>
ra...@gmail.com <ra...@gmail.com> #12
Why did the one get obsolete? The issue still occurs.
[Deleted User] <[Deleted User]> #13
[Comment deleted]
vu...@gmail.com <vu...@gmail.com> #14
I have found this issue also on multiple devices.
ma...@gmail.com <ma...@gmail.com> #15
I, too, would like to know why this got obsoleted.
Are we expected to just move on with no explanation or workaround?
Confirmed on Galaxy Note (4.1.2) and some 4.2.2
Are we expected to just move on with no explanation or workaround?
Confirmed on Galaxy Note (4.1.2) and some 4.2.2
mr...@gmail.com <mr...@gmail.com> #16
It's probably obsolete due to the introduction of Toolbar.
bo...@gmail.com <bo...@gmail.com> #17
That is not a problem of Toolbar but of SearchView itself. Even in the Support-Library.
bo...@gmail.com <bo...@gmail.com> #18
In response to comments #12,15,16: My guess is the issue was deemed obsolete because notification equivalent to onClose is provided by MenuItemCompat.OnActionExpandListener.onMenuItemActionCollapse. See example in section "Handling Collapsible Action Views" of http://developer.android.com/guide/topics/ui/actionbar.html#ActionView
va...@gmail.com <va...@gmail.com> #19
Still have to deal with this shit after all these *********** years!
va...@gmail.com <va...@gmail.com> #20
No issue solving why to raise the issue firstly ?
gr...@gmail.com <gr...@gmail.com> #21
Same issue. setOnCloseListener not working when menu app:showAsAction="collapseActionView|ifRoom"
but when i remove collapseActionView it starts working.
but when i remove collapseActionView it starts working.
Description
On 4.0 device (Galaxy Nexus) onClose callback is NOT called.
My manifest, minSdkVersion="13", taragetSdkVersion="14"
Have a SearchView menu item:
<item android:id="@+id/menu_search"
android:showAsAction="always"
android:orderInCategory="1"
android:actionViewClass="android.widget.SearchView" />
in onCreateOptionsMenu set a close listener on the SearchView
final SearchView searchView = (SearchView) searchMenu.getActionView();
searchView.setOnCloseListener(new OnCloseListener() {
@Override
public boolean onClose() {...});
See