in Java File
private ArrayList<AddItem> arrayTitle;
private ArrayList<AddItem> searchTitle;
arrayTitle = new ArrayList<AddItem>();
searchTitle = new ArrayList<AddItem>();
edttitle.addTextChangedListener(new SearchTextWatcher());
public class SearchTextWatcher implements TextWatcher {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
String strSearch = edttitle.getText().toString();
if (searchTitle != null)
searchTitle.clear();
if (arrayTitle != null && arrayTitle.size() > 0)
{
for (AddItem itemModel : arrayTitle)
{
if (itemModel.getTitleName().trim().toLowerCase().contains(strSearch.trim().toLowerCase()))
{
searchTitle.add(itemModel);
}
}
adapter.setTitles(searchTitle);
adapter.notifyDataSetChanged();
}
}
}
In Adapter
public void setTitles(ArrayList<AddItem> titles) {
this.arrayItem = titles;
}
public ArrayList<AddItem> getList() {
return arrayItem;
}
private ArrayList<AddItem> arrayTitle;
private ArrayList<AddItem> searchTitle;
arrayTitle = new ArrayList<AddItem>();
searchTitle = new ArrayList<AddItem>();
edttitle.addTextChangedListener(new SearchTextWatcher());
public class SearchTextWatcher implements TextWatcher {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
String strSearch = edttitle.getText().toString();
if (searchTitle != null)
searchTitle.clear();
if (arrayTitle != null && arrayTitle.size() > 0)
{
for (AddItem itemModel : arrayTitle)
{
if (itemModel.getTitleName().trim().toLowerCase().contains(strSearch.trim().toLowerCase()))
{
searchTitle.add(itemModel);
}
}
adapter.setTitles(searchTitle);
adapter.notifyDataSetChanged();
}
}
}
In Adapter
public void setTitles(ArrayList<AddItem> titles) {
this.arrayItem = titles;
}
public ArrayList<AddItem> getList() {
return arrayItem;
}