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.
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.
You can use a TextWatcher to listen for text changes on the EditText and then update the contents of your GridView ASAP.
// 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) {}
});
After you have filtered your data somehow, just update the contents set on your custom Adapter
// Changes the data used inside your custom adapter
public void update(ArrayList<MyDataClass> filteredDataList){
if(filteredDataList != null){
adapterDataList = filteredDataList;
}
}