3

I have custom grid adapter which contains image and text(Custom Object),on top of Gridview I have added Edittext, I would like add search functionality when ever user enter text in Edittext.

Any help greatly appreciated.

4

1 回答 1

4

您可以使用TextWatcher侦听 EditText 上的文本更改,然后尽快更新 GridView 的内容。

    // Perform search
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            performSearch(s.toString());
        }

        @Override
        public void afterTextChanged(Editable s) { }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
    });

以某种方式过滤数据后,只需更新自定义适配器上设置的内容

// Changes the data used inside your custom adapter
public void update(ArrayList<MyDataClass> filteredDataList){
    if(filteredDataList != null){
        adapterDataList = filteredDataList;
    }
}
于 2013-09-02T17:16:32.340 回答