2014-01-07 14 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> 
相關問題