【问题标题】:Filter Text in ExpandableListView using BaseExpandableListAdapter使用 BaseExpandableListAdapter 过滤 ExpandableListView 中的文本
【发布时间】:2012-02-22 03:15:36
【问题描述】:

我需要你的帮助 :) 我有一个 EditText,下面有一个 ExpandableListView。我使用了带有组/子的 BaseExpandableListAdapter。我希望当用户在 EditText 中写入时,ExpandableListView 仅显示插入文本的组(项目)。 我认为我必须创建一个过滤器。 这里有一段我​​的源代码。有人可以帮我吗?提前谢谢你

         @Override
     public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState
               setContentView(R.layout.main);
               et = (EditText) findViewById(R.id.filterText);

               et.setSingleLine();  
               et.addTextChangedListener(new TextWatcher() {

        @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (et.getText().toString().equals(""))
                elv.setBackgroundColor(Color.BLACK);
            else
            {
                elv.setBackgroundColor(Color.WHITE);
            }
        }
             @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

        }
    });

            elv=getExpandableListView();
            mAdapter = new MyExpandableListAdapter(fields_select,description);
            elv.setAdapter(mAdapter);

            class MyExpandableListAdapter extends BaseExpandableListAdapter {
               ......
            }

【问题讨论】:

    标签: android filter android-edittext adapter expandablelistview


    【解决方案1】:

    我解决了,我是这样实现接口Filterable的:

       class MyExpandableListAdapter extends BaseExpandableListAdapter implements Filterable{
    

    然后我重写了 getfilter() 方法。最后,我写了一个扩展Filter类的类。

       public Filter getFilter() {
        Filter filter = new MyFilter();
        return filter;
    }
    
        private class MyFilter extends Filter{
    

    【讨论】:

      猜你喜欢
      • 2011-08-19
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多