add filter listview on edit text with base adapter
<p>i have a base adapter and i want to filter my list view my list is already showing but when i type in edit text the list doesnt filter instead it toast the message you type in the edit text box what i wanted is filter the list when you type in the edit text box if there are similar char sequence to the text you type in the edit text box the list will show all the similar text.any suggestion here is my code </p>

<p>base adapter</p>

<pre><code>package com.martinlloyd.mygears;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

public class PoliceListAdapter extends BaseAdapter implements Filterable {


     //Two data sources, the original data and filtered data
   private ArrayList&lt;PoliceDetails&gt; originalData;
   private ArrayList&lt;PoliceDetails&gt; filteredData;
    private ArrayList&lt;PoliceDetails&gt; PoliceArray;   
    List&lt;String&gt; mOriginalValues; // Original Values
    LayoutInflater inflater;

    public PoliceListAdapter(Context context, ArrayList&lt;PoliceDetails&gt; police_details) {
        this.PoliceArray = police_details;
        inflater = LayoutInflater.from(context);
        originalData = police_details;
        filteredData = police_details;


    }
    @Override
    public int getCount() {
        return PoliceArray.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    static class ViewHolder {
        TextView name;
        TextView area;
        TextView address;
        TextView id;
        TextView phonenumber;

    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.dirlist, null);
            holder = new ViewHolder();
            //holder.id = (TextView) convertView.findViewById(R.id.dirtvid);
            holder.name = (TextView) convertView.findViewById(R.id.dirtvname);
            holder.address = (TextView) convertView.findViewById(R.id.dirtvaddress);
            holder.area = (TextView) convertView.findViewById(R.id.dirtvarea);
            holder.phonenumber = (TextView) convertView.findViewById(R.id.dirtvphone);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //holder.id.setText(HospitalArray.get(position).getId());
        holder.name.setText(PoliceArray.get(position).getName());
        holder.address.setText(PoliceArray.get(position).getAddress());
        holder.area.setText(PoliceArray.get(position).getArea());
        holder.phonenumber.setText(PoliceArray.get(position).getPhonenumber());

        return convertView;

    }
    public Filter getFilter()
    {
       return new Filter()
       {
            @Override
            protected FilterResults performFiltering(CharSequence charSequence)
            {
                FilterResults results = new FilterResults();

                //If there's nothing to filter on, return the original data for your list
                if(charSequence == null || charSequence.length() == 0)
                {
                    results.values = originalData;
                    results.count = originalData.size();
                }
                else
                {
                    ArrayList&lt;PoliceDetails&gt; filterResultsData = new ArrayList&lt;PoliceDetails&gt;();

                    for(PoliceDetails data : originalData)
                    {
                        //In this loop, you'll filter through originalData and compare each item to charSequence.
                        //If you find a match, add it to your new ArrayList
                        //I'm not sure how you're going to do comparison, so you'll need to fill out this conditional
                        if(charSequence == data.getName())
                        {
                            filterResultsData.add(data);
                        }
                    }            

                    results.values = filterResultsData;
                    results.count = filterResultsData.size();
                }

                return results;
            }

            @SuppressWarnings("unchecked")
            @Override
            protected void publishResults(CharSequence charSequence, FilterResults filterResults)
            {
                filteredData = (ArrayList&lt;PoliceDetails&gt;)filterResults.values;
                notifyDataSetChanged();
            }
        };
    }
    public static void setAdapter(ArrayAdapter&lt;String&gt; adapter) {
        // TODO Auto-generated method stub

    }
}



package com.martinlloyd.mygears;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class DirectoryPolice extends Activity {



    // Search EditText
    EditText inputSearch;


    /** An array of strings to populate dropdown list */
    String[] actions = new String[] {
        "",
        "Profile",
        "Breaking News",
        "Weather Update",
        "Directory",
        "Emergency Call",
        "Share A News",

    };

    ListView list_view_main;
    ProgressDialog pd=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.directorypolice);

    final EditText filterEditor = (EditText) findViewById(R.id.filter);

    filterEditor.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if(s.length()==0){
                list_view_main.clearTextFilter();
            }
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after){
        }
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {
            list_view_main.setTextFilterEnabled(true);
            list_view_main.setFilterText(s.toString());
        }
    });




        /** Create an array adapter to populate dropdownlist */
        ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, actions);


        /** Enabling dropdown list navigation for the action bar */
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        /** Defining Navigation listener */
        ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {

            @Override
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                Intent o = null;
                switch (itemPosition)
                {
                case 0:
                    break;

                case 1:
                    o = new Intent(getApplicationContext(), Profile.class);
                    startActivity(o);
                    break;
                case 2:
                    o = new Intent(getApplicationContext(), BreakingNews.class);
                    startActivity(o);
                    break;
                case 3:
                    o = new Intent(getApplicationContext(), WeatherToday.class);
                    startActivity(o);
                    break;
                case 4:
                    o = new Intent(getApplicationContext(), DirectoryListing.class);
                    startActivity(o);
                    break;
                case 5:
                    o = new Intent(getApplicationContext(), EmergencyCallListing.class);
                    startActivity(o);
                    break;
                case 6:
                    o = new Intent(getApplicationContext(), ShareAnews.class);
                    startActivity(o);
                    break;
                }
                return false;
            }
        };

        /** Setting dropdown items and item navigation listener for the actionbar */
        getActionBar().setListNavigationCallbacks(adapter, navigationListener);        
        this.pd = ProgressDialog.show(this, "Directory Police.", "Please wait while fetching data...");
        GetAllPolice();
    }
    private void GetAllPolice() {
        (new fetchDirectoryPolice(this)).execute();
    }
    private class fetchDirectoryPolice extends AsyncTask&lt;Void, ArrayList&lt;PoliceDetails&gt;, ArrayList&lt;PoliceDetails&gt;&gt; {

        @SuppressWarnings("unused")
        Context mContext;

        public fetchDirectoryPolice(Context context) {
            super();

            mContext = context;

        }

        ArrayList&lt;PoliceDetails&gt; search_results = new ArrayList&lt;PoliceDetails&gt;();
        PoliceDetails police_details;

        @Override
        protected ArrayList&lt;PoliceDetails&gt; doInBackground(Void... params) {

            try{

                // Create a new HTTP Client
                DefaultHttpClient defaultClient = new DefaultHttpClient();
                // Setup the get request
                HttpGet httpGetRequest = new HttpGet("url here");

                // Execute the request in the client
                HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
                // Grab the response
                BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
                String json = reader.readLine();

                JSONArray jsonArray = new JSONArray(json);

                for(int i = 0; i &lt; jsonArray.length(); i++) {
                    JSONObject row = jsonArray.getJSONObject(i);
                    //JSONArray row = jsonArray.getJSONArray(0);
                    //row.getString(index)
                    police_details = new PoliceDetails();
                    police_details.setId(row.getString("id"));
                    police_details.setName(row.getString("name"));
                    police_details.setAddress(row.getString("address"));
                    police_details.setArea(row.getString("area"));
                    police_details.setPhonenumber(row.getString("phonenumber"));

                    search_results.add(police_details);
                }

            } catch(Exception e){

                e.printStackTrace();

            }

            return search_results;
        }

        protected void onPostExecute(ArrayList&lt;PoliceDetails&gt; search_results) {
            if(DirectoryPolice.this.pd != null){
                DirectoryPolice.this.pd.dismiss();
            }
            ArrayList&lt;PoliceDetails&gt; police_details = search_results;
            list_view_main = (ListView)findViewById(R.id.policelist);
            list_view_main.setAdapter(new PoliceListAdapter(getApplicationContext(), police_details));
            list_view_main.setClickable(true);
            list_view_main.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
                    TextView c = (TextView) v.findViewById(R.id.dirtvphone);
                    String q = "tel:" +("02"+ c.getText().toString());

                    if(c.getText().equals(""))
                    {
                            Toast.makeText(DirectoryPolice.this,"No Contact Number Available", Toast.LENGTH_SHORT).show();

                     }else {
                            Intent intent = new Intent(Intent.ACTION_CALL);  
                            intent.setData(Uri.parse(q));  
                            startActivity(intent);

                     }
                }
            });
        }

    }
}
</code></pre>
