2013-07-11 83 views
0

我有一個問題,它似乎只有我有它。我已經實現了textwatcher,當我在listview中過濾一個字符串時,它在列表中顯示了兩次對象。Textwatcher過濾列表

這我在做什麼

filterText = (EditText) findViewById(R.id.EditText01); 
filterText.addTextChangedListener(filterTextWatcher); 

,這裏是適配器和textwatcher。

 adapter2 = new SimpleAdapter(ListBased.this, ListBasedList, 
       R.layout.list_item,new String[] 
         { TAG_Location_Name, TAG_Address, TAG_Dist, TAG_Postal, TAG_Location_id, TAG_City, TAG_Company_id, TAG_Lat, TAG_Lng}, new int[] { 
         R.id.location_name, R.id.location_adress, R.id.dist, R.id.postal, R.id.location_location_id, R.id.location_city, R.id.location_company_id, R.id.lat, R.id.lng}); 
        setListAdapter(adapter2); 
    } 
} 

private TextWatcher filterTextWatcher = new TextWatcher() 
{ 
    public void afterTextChanged(Editable s) { 
     } 
    public void beforeTextChanged(CharSequence s, int start, int count, 
      int after) { 
    } 
    public void onTextChanged(CharSequence s, int start, int before, 
      int count) { 
     adapter2.getFilter().filter(s); 
    } 
}; 

它的工作很好像打字,但這裏是一個截圖如何顯示它。

屏幕截圖here

任何人都可以解釋我的問題?

回答

1

我有同樣的問題。我想到了。這是由於你在名單和城市字段中有相同的文字「Sindal」。

+0

是的,這是真的。我花了我的時間來找出爲什麼它是這樣的。但我已經做了一個適配器,幫助我解決了這個問題。 – Tirolel

+0

哪個適配器?你能分享你的代碼....謝謝你 – donison24x7

+0

我會盡力找到它明天發佈它作爲答案在這裏。 – Tirolel