title: Searching a ListView does not work - why?
body: <p>Hi I have a listView in a Dialog, and I have setup a custom adapter for the Dialog. </p>
  
  <p>I lookup up and I setup the addTextChangedListener but does not seem to work.</p>
  
  <p>I just want to search through the list and refresh the list when the user types in the Edit text</p>
  
  <p>Any idea where I am getting it wrong please</p>
  
  <p>Here is my code</p>
  
  <pre><code>private void showCompaniesDialog(List&lt;Company&gt; companies) {
      if(companies != null) {
          final Dialog dialog = new Dialog(getContext());
          // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
          dialog.setCancelable(false);
          dialog.setContentView(R.layout.dialog_company_listview);
  
          Button btndialog = (Button) dialog.findViewById(R.id.btndialog);
          btndialog.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  dialog.dismiss();
              }
          });
  
          ListView listView = (ListView) dialog.findViewById(R.id.listview);
          //ArrayAdapter arrayAdapter = new ArrayAdapter(getContext(), R.layout.company_list_item, R.id.tv, companies);
          CompanyAdapter companyAdapter = new CompanyAdapter(getActivity(), 0, companies);
          listView.setAdapter(companyAdapter);
  
          //HERE I SET THE TEXT FILTER ENABLED
          listView.setTextFilterEnabled(true);
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  //textView.setText("You have clicked : " + companies[position]);
                  dialog.dismiss();
              }
          });
  
          //HERE I ADD CHANGED LISTENER
          EditText etSearch = (EditText) dialog.findViewById(R.id.etSearch);
          etSearch.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                  //companyAdapter.getFilter().filter(charSequence.toString());
              }
  
              @Override
              public void afterTextChanged(Editable editable) {
                  companyAdapter.getFilter().filter(editable);
              }
          });
  
          dialog.show();
      }
  
  }
  </code></pre>
  
  <p>Here is the custom adapter for the company</p>
  
  <pre><code>public class CompanyAdapter extends ArrayAdapter&lt;Company&gt;{
      private Activity activity;
      private List&lt;Company&gt; lCompany;
      private LayoutInflater inflater = null;
  
      public CompanyAdapter (Activity activity, int textViewResourceId, List&lt;Company&gt; lCompany){
          super(activity, textViewResourceId, lCompany);
          try{
              this.activity = activity;
              this.lCompany = lCompany;
  
              inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          }catch (Exception e){
              e.printStackTrace();
          }
      }
  
      public int getCount(){
          return lCompany.size();
      }
  
      public Company getItem (Company position){
          return position;
      }
  
      public  long getItemId(int position){
          return position;
      }
  
      public  class ViewHolder {
          public TextView display_name;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          View vi = convertView;
          final ViewHolder holder;
          try {
              if (convertView == null) {
                  vi = inflater.inflate(R.layout.company_list_item, null);
                  holder = new ViewHolder();
  
                  holder.display_name = (TextView) vi.findViewById(R.id.tvCompanyName);
  
  
                  vi.setTag(holder);
              } else {
                  holder = (ViewHolder) vi.getTag();
              }
              holder.display_name.setText(lCompany.get(position).getName());
  
          } catch (Exception e) {
              e.printStackTrace();
  
          }
          return vi;
      }
  }
  </code></pre>
  
  <p>Any suggestions would be very helpful</p>