title: Implementing AutoComplete with ListView in Android
body: <p>I was following this example:</p>
  
  <p><a href="http://developer.android.com/resources/tutorials/views/hello-autocomplete.html" rel="noreferrer">http://developer.android.com/resources/tutorials/views/hello-autocomplete.html</a></p>
  
  <p>And I want to know how I can implement this with a ListView instead of the dropdown window that is supplied with this TextView.</p>
  
  <p>For instance, as the user types into the textView, there is a ListView directly below the textView that will be constantly changing as the user types in the textView field.</p>
  
  <p>EDIT: Here is the solution that I coded with thanks to Josephus:</p>
  
  <pre><code>package com.jaylefler.contacts;
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  
  public class ContactProjectActivity extends Activity {
      /** Called when the activity is first created. */
  
      // List of all contacts
      private ArrayList&lt;String&gt; searchNames = new ArrayList&lt;String&gt;();
      // Filtered list of contacts after user begins typing in search field
      private ArrayList&lt;String&gt; partialNames = new ArrayList&lt;String&gt;();
  
      // List of names matching criteria are listed here
      private ListView myList;
  
      // Field where user enters his search criteria
      private EditText nameCapture;
  
      // Adapter for myList
      private ArrayAdapter&lt;String&gt; adapter;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          // Set list adapter
          myList = (ListView) findViewById(R.id.names);
          adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, partialNames);
          myList.setAdapter(adapter);
  
          searchNames.add("Tom Arnold");
          searchNames.add("Zeb Arnold");
          searchNames.add("Dan Bateman");
          searchNames.add("Tommy Canders");
          searchNames.add("Elijah Arnman");
          searchNames.add("Tomas Muster");
          searchNames.add("Stefan Edberg");
          searchNames.add("Ivan Lendl");
  
  
          nameCapture = (EditText) findViewById(R.id.name);
          nameCapture.setText("Tom");
  
          AlterAdapter();
  
          nameCapture.addTextChangedListener(new TextWatcher() {
  
              // As the user types in the search field, the list is
              @Override
              public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                  AlterAdapter();
              }
  
              // Not used for this program
              @Override
              public void afterTextChanged(Editable arg0) {
  
              }
  
              // Not uses for this program
              @Override
              public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                  // TODO Auto-generated method stub
  
              }
          });
      }
  
      // Filters list of contacts based on user search criteria. If no information is filled in, contact list will be blank.
      private void AlterAdapter() {
          if (nameCapture.getText().toString().isEmpty()) {
              partialNames.clear();
              adapter.notifyDataSetChanged();
          }
          else {
              partialNames.clear();
              for (int i = 0; i &lt; searchNames.size(); i++) {
                  if (searchNames.get(i).toString().toUpperCase().contains(nameCapture.getText().toString().toUpperCase())) {
                      partialNames.add(searchNames.get(i).toString());
                  }
                  adapter.notifyDataSetChanged();
              }
          }
      }
  }
  </code></pre>