我的應用程序有一個twoline ListView與自定義適配器。我想用輸入到EditText過濾listview內容。這怎麼可能?使用自定義適配器搜索列表視圖
lv.setAdapter(new MyCustomBaseAdapter(getActivity(),recordObjects));
//recordObjects is an ArrayList of objects
我的應用程序有一個twoline ListView與自定義適配器。我想用輸入到EditText過濾listview內容。這怎麼可能?使用自定義適配器搜索列表視圖
lv.setAdapter(new MyCustomBaseAdapter(getActivity(),recordObjects));
//recordObjects is an ArrayList of objects
你必須設置TextWatcher to your EditText
和
,然後使用動態數組篩選數據...
使用addTextChangedListener
方法將TextWatcher
添加到您的EditText
。然後在執行onTextChanged
時,根據需要添加或刪除ListView
的適配器中的項目。
這是你想要的東西嗎?
ListView lv = getListView();
/* Gets a ListView */
lv.setTextFilterEnabled(true);
/* sorts the listview */
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_list_item_1,
result.getheadlines());
setListAdapter(adapter);
/*
* gets the lisadapter from the XML and sets it equal to
* whatever result is
*/
[這裏是同一個答案(http://stackoverflow.com/questions/8678163 /列表過濾器定製適配器,不要放棄的結果/ 8678198#8678198) –