2016-07-15 32 views
1

我正在使用搜索視圖。它之前工作,它沒有響應,我不能看到在搜索視圖中輸入的任何文本,也不會在文本發生更改時收回任何回調。Android搜索查看未顯示任何文本

這裏是XML佈局文件,

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.SearchView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:iconifiedByDefault="false" 
      android:id="@+id/searchView"/> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/cardsRecyclerView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/transparent" 
      android:cacheColorHint="@android:color/transparent"/> 
    </LinearLayout> 

這裏是我如何設置搜索查看回調,

EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); 
     searchEditText.setTextColor(getResources().getColor(R.color.colorPrimary)); 
     searchEditText.setHintTextColor(getResources().getColor(R.color.dark_grey)); 
searchView.setOnQueryTextListener(this); 

我沒有得到任何回調這些方法,當我在搜索查看類型。

@Override 
    public boolean onQueryTextSubmit(String query) { 
     return false; 
    } 

    @Override 
    public boolean onQueryTextChange(String newText) { 
     filterCards(newText); 
     return false; 
    } 

我在我的Fragment中實現了SearchView.OnQueryTextListener。

謝謝。

+0

您是否試過我的解決方案? –

+0

請顯示'filterCards(newText);' –

+0

@SohailZahid當我輸入到SearchView時從未觸發該方法 – Zach

回答

0

儘量給,

android:textColor="#000000" 

android.support.v7.widget.SearchView

Note :可能是你的文字是白色的,這就是爲什麼你不能看到。

+0

我不認爲它的文字顏色,正如你所看到的,我正在改變代碼中的文字顏色。我也試過你的解決方案。沒有工作。如果它的文字顏色,那麼我應該回調給偵聽器方法。那沒有發生 – Zach