-1
我想問你一些指針,尋找我的問題的解決方案,因爲谷歌搜索過去幾個小時沒有幫助。SearchView也被「隱藏」關鍵字的ListView搜索
我有一個SearchView
和ExpandableListView
和一切工作正常。 對於我的每一個列表(String
s)我想添加不會顯示的關鍵字,但可以搜索。
例如,如果我們有水果的清單:
-Apple
-Banana
-Orange
...
我想將它們分配隱藏關鍵字,如:
-Apple (healthy)
-Banana (tasty)
-Orange (sour)
所以,當我鍵入進入我的SearchView
:「健康」,它只會顯示蘋果。
我的一些代碼(SearchView
):
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
search = (SearchView) findViewById(R.id.search);
search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
search.setIconifiedByDefault(false);
search.setOnQueryTextListener(this);
search.setOnCloseListener(this);
和ArrayList
:
ArrayList<Fruit> fruitList = new ArrayList<Fruit>();
Fruit fruit = new Fruit("Apple", R.drawable.apple);
fruitList.add(fruit);
fruit = new Fruit("Orange", R.drawable.orange);
fruitList.add(fruit);
fruit = new Fruit("Banana", R.drawable.banana);
fruitList.add(fruit);
Basket basket = new Basket("Yes",basketList);
basketList.add(basket);
fruitList = new ArrayList<Fruit>();
Fruit fruit = new Fruit("Peach", R.drawable.peach);
fruitList.add(fruit);
fruit = new Fruit("Pineapple", R.drawable.pineapple);
fruitList.add(fruit);
fruit = new Fruit("Coconut", R.drawable.coconut);
fruitList.add(fruit);
Basket basket = new Basket("No",basketList);
basketList.add(basket);
...
這是一個問題類:'水果{name,attr}'僞代碼:'List searchByNameOrAttr(List input,string lookingFor){return input.selectAll(x => x.name.similarTo(lookingFor)|| || x.attr.similarTo(lookingFor)); }'similarTo可以是startsWith或contains和'x => x.name ...'意思是比較器實現 –
Selvin
2015-01-15 17:55:56