1

This question is a follow up to Show android SearchView EditText by default. My SearchView used to work fine until I added android:iconifiedByDefault="false" to the layout. Now, when I click on the icon or type in the search field, no search takes place. Does anyone know how to fix this problem? here is my SearchView as it exists now.

<SearchView
    android:id="@+id/search"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:queryHint="@string/search_hint"
    android:iconifiedByDefault="false"
    android:textSize="16sp" />

I already tried the following:

mSearch.setOnSearchClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onSearchRequested();
        //other stuff happen here
        }
    });
Community
  • 1
  • 1
user3093402
  • 1,419
  • 4
  • 20
  • 28

2 Answers2

0

I solved the problem with

public void onFocusChange(View v, boolean hasFocus) {
  if (hasFocus) { ...}
}
user3093402
  • 1,419
  • 4
  • 20
  • 28
0

i solve this problem by simply adding requestFocus tag in SearchView widget.

    <SearchView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/search"
    android:clickable="true"
    android:queryHint="Enter Song name.."
    android:iconifiedByDefault="false">

    <requestFocus/>

</SearchView>
Abhishek Garg
  • 3,092
  • 26
  • 30