list = (ListView) findViewById(R.id.list_Upadates); // Pass the results into ListViewAdapter.java adapter = new UpdatesAdapterList(Cardiology_updates.this, FinalLocalDataList); // Set the adapter to the ListView list.setAdapter(adapter); // adapter.notifyDataSetChanged(); et = (EditText) findViewById(R.id.search); // Capture Text in EditText et.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { //String text = et.getText().toString().toLowerCase(Locale.getDefault()); adapter.getFilter().filter(arg0); } }); } }
@Override public Filter getFilter() { if(valueFilter==null) { valueFilter=new ValueFilter(); } return valueFilter; } private class ValueFilter extends Filter { //Filter filter = new Filter() { ArrayList> filteredList; @Override protected FilterResults performFiltering(CharSequence constraint) { // Holds the results of a filtering operation in values FilterResults results=new FilterResults(); if(constraint!=null && constraint.length()>0){ filteredList= new ArrayList>(); //This is the search string user typed in EditText. // String searchString = constraint.toString().startsWith(prefix).toUpperCase(Locale.getDefault()); /* * Code to update the filteredList based on Search String. * * I'm just writing pseudo code for search, based on * Cardiology_updates.UpdateTitle */ int mCount=data.size(); for (int i = 0; i < mCount; i++) { HashMap obj= data.get(i); String updateTitle=obj.get(Cardiology_updates.UpdateTitle); if(updateTitle.toUpperCase().startsWith(constraint.toString().toUpperCase())){ filteredList.add(obj); } } results.count = filteredList.size(); results.values = filteredList; }else{ // set the Filtered result to return results.count = filteredList.size(); results.values = filteredList; } return results; } @Override protected void publishResults(CharSequence constraint, FilterResults results) { // Has the filtered values data = (ArrayList>) results.values; notifyDataSetChanged(); } }; }
adapter.getFilter().filter(arg0);
Filter
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)