here is my code :
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.activity_main, null);
llMain = (LinearLayout) view.findViewById(R.id.llMain);
llMain.setBackgroundColor(Color.GRAY);
InputSearch=(EditText)view.findViewById(R.id.search);
InputSearch.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapter.getFilter().filter(s);// Error on this line: create method getFilter() in customadapter
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
});
}
答案 0 :(得分:1)
将第adapter.getFilter().filter(s);
行更改为MyActivity.this.adapter.getFilter().filter(s);
答案 1 :(得分:0)
您必须为自定义适配器实现Filterable并覆盖getFilter()方法。
public CustomAdapter extends BaseAdapter implements Filterable
{
//override all adapter methods
@Override
public Filter getFilter() {
// your code here
return null;
}
}