How to create a custom filter in the android lestview that looks for words after the space character

1

In this code the filter is working until the first word. From the moment I type the space character the filter stops working. Example: Search for "Steve Jobs", the system gets lost. Now if you search only until "Steve" it returns right.

ArrayList<> dados = new ArrayList<>();

SQLiteDatabase db1 = base.getReadableDatabase();

  Cursor c = db1.rawQuery("SELECT * FROM produtos WHERE pcodgrupo LIKE '2' ORDER BY pcodprod ",null);

   while (c.moveToNext())
      {
          HashMap map = new HashMap();
          map.put("pcodprod", c.getString(0));
          map.put("pdescricao", c.getString(2));
          map.put("compl", c.getString(5));
          map.put("pprecovenda", c.getString(9));
          map.put("plocalizacaoprod", c.getString(25));
          map.put("pprecoprazo", c.getString(c.getColumnIndex("pprecoprazo")));
          dados.add(map);
      }

String[] from = new String[]{"pcodprod", "plocalizacaoprod", "pdescricao", "compl", "pprecovenda","pprecoprazo"};

 int layout = R.layout.list_teste_item2;

 int[] to = new int[]{R.id.id, R.id.localP, R.id.nome, R.id.comple, R.id.prevoAv, R.id.precoPrazo};

ListView lv = (ListView) findViewById(R.id.listView2);

adapter = new SimpleAdapter(this, dados, layout, from, to);
lv.setAdapter(adapter);


 edtPesquisa.addTextChangedListener(new TextWatcher() {
 @Override
 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
 @Override
 public void onTextChanged(CharSequence s, int start, int before, int count) {
     adapter.getFilter().filter(s.toString().trim());
 }
 @Override
 public void afterTextChanged(Editable s) {

 }
    
asked by anonymous 31.10.2016 / 14:35

1 answer

0

SimpleAdapter does not support some filters, change to ArrayAdapter , or use a custom adapter, for example implements Filterable , so it allows a good amount of filters.

    
31.10.2016 / 16:35