2016-08-05 41 views
0

我使用工具欄searchview。我使用代碼捕獲輸入結果:如何在SearchView中顯示搜索結果

SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { 
     public boolean onQueryTextChange(String newText) { 

      return true; 
     } 

當我得到結果時,我正在尋找我的excel文件中的類似字符串。然後我返回ArrayList(搜索結果)。現在我需要在SearchView中顯示結果。我該怎麼做?

回答

1

您需要使用與您的searchview關聯的CursorAdapter。

Searchview.setSuggestionAdapter 

約光標從一個數組(Create a cursor from hardcoded array instead of DB)的使用有用的鏈接。

+0

感謝您的回答。當我創建SimpleCursorAdapter時,我需要「到」數組,但我需要在SearchView中顯示搜索結果。我無法理解如何填寫正確的SimpleCursorAdapter? – Delphian

+0

在創建SimpleCursorAdapter並將它與onCreateOptionsMenu中的SearchView關聯後,您需要使用SearchView.setQueryTextListener偵聽更改。在此回調(onQueryTextChange)中,您可以從數據中創建一個新的遊標,並使用CursorAdapter.swapCursor將新遊標傳遞給cursoradapter。 – Jacob