2014-01-07 13 views
0

此问题是后续到Show android SearchView EditText by default。我的SearchView用于正常工作,直到我将android:iconifiedByDefault="false"添加到布局。现在,当我点击图标或输入搜索字段时,不会进行搜索。有谁知道如何解决这个问题?这是我的SearchView,因为它现在存在。在Android SearchView原因视图设置图标化为false无法搜索

<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" /> 

我已经试过如下:

mSearch.setOnSearchClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      getActivity().onSearchRequested(); 
     //other stuff happen here 
     } 
    }); 

回答

0

我只需在搜索查看小部件添加requestFocus的标签与

public void onFocusChange(View v, boolean hasFocus) { 
    if (hasFocus) { ...} 
} 
0

我解决这个问题解决了这个问题。

<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> 
相关问题