如何在片段 class 中的编辑文本上添加文本更改侦听器

how to add text changed listener on Edit text in fragment class

在我的片段 class 中自定义 listview.I 也有一个编辑文本,用于过滤文本更改的列表记录。但有些我无法在 fragmnet

中实现它
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

        }
    });
}

将行adapter.getFilter().filter(s);更改为MyActivity.this.adapter.getFilter().filter(s);

您必须为 CustomAdapter 和 ovverride getFilter() 方法实现 Filterable。

public CustomAdapter extends BaseAdapter implements Filterable 
{
     //override all adapter methods

     @Override
    public Filter getFilter() {

        // your code here
        return null;
    }
}