2012-05-19 109 views
0

我的應用程序有一個twoline ListView自定義適配器。我想用輸入到EditText過濾listview內容。這怎麼可能?使用自定義適配器搜索列表視圖

lv.setAdapter(new MyCustomBaseAdapter(getActivity(),recordObjects)); 
//recordObjects is an ArrayList of objects 
+1

[這裏是同一個答案(http://stackoverflow.com/questions/8678163 /列表過濾器定製適配器,不要放棄的結果/ 8678198#8678198) –

回答

1

你必須設置TextWatcher to your EditText

,然後使用動態數組篩選數據...

0

使用addTextChangedListener方法將TextWatcher添加到您的EditText。然後在執行onTextChanged時,根據需要添加或刪除ListView的適配器中的項目。

0

這是你想要的東西嗎?

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 
      */ 
相關問題