Android listview edittext filter space button?

后端 未结 2 1650
误落风尘
误落风尘 2020-12-21 18:43

I have created a filter listview where user will enter input via edittext and results are filtered in the listview.

The code is running good but when ever i press Sp

相关标签:
2条回答
  • 2020-12-21 19:14

    do this way:

    public void afterTextChanged(Editable s) {
        String st = s.toString().trim();            
        NearByActivity.this.aa.getFilter().filter(st);
    }
    

    but don't do filtering this way, here is the correct one.

    0 讨论(0)
  • 2020-12-21 19:14

    I found solution:

    String[] hi={"Hi there", "Hello", "Bye"};
    
    adapter = new ArrayAdapter<String>(slownik.this, R.layout.list_item, R.id.word_name,hi);
    lv.setAdapter(adapter);
    
    inputSearch.addTextChangedListener(new TextWatcher() {
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
    
            lv.setTextFilterEnabled(true);
            lv.setFilterText(s.toString().trim());
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
    
        }
    
        @Override
        public void afterTextChanged(Editable s) {
            slownik.this.adapter.getFilter().filter(s.toString().trim());
            if(s.length()==0){
                lv.clearTextFilter();
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题