【问题标题】:Textwatcher filtering listTextwatcher 过滤列表
【发布时间】:2013-07-11 12:45:53
【问题描述】:

我有一个问题,似乎只有我一个人有这个问题。我已经实现了 textwatcher,当我在 listview 中过滤字符串时,它会在列表中显示该对象两次。

这就是我正在做的事情

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

这是适配器和文本观察器。

        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!

谁能解释一下这个问题?

【问题讨论】:

    标签: android listview textwatcher


    【解决方案1】:

    我遇到了同样的问题。我想到了。这是因为您在列表的名称和城市字段中具有相同的文本“Sindal”。

    【讨论】:

    • 是的,这是真的。我花了一些时间才弄清楚为什么会这样。但我做了一个适配器,帮助我解决了这个问题。
    • 我明天会尝试找到它并将其作为答案发布在这里。
    猜你喜欢
    • 2020-04-05
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 2015-02-28
    • 2023-03-23
    • 2013-09-29
    • 2021-04-18
    • 2010-10-06
    相关资源
    最近更新 更多