title: AutoCompleteTextView with OnKeyListener
body: <p>I have a <code>AutoCompleteTextView</code> and I have set <code>OnItemClick</code>, but now I want to set <code>OnKeyListener</code> for search button. I have searched but haven't found anything to help me out.</p>
  
  <p>Here's my auto complete xml:</p>
  
  <pre><code>    &lt;AutoCompleteTextView 
                  android:id="@+id/autocomplete_stores" 
                  android:layout_width="fill_parent" 
                  android:layout_height="60dp" 
                  android:layout_marginBottom="5dp"
                  android:hint="Stores Search:" 
                  android:singleLine="true" 
                  android:ellipsize="end"
                  android:imeOptions="actionSearch" /&gt;
  </code></pre>
  
  <p>And the java code:</p>
  
  <pre><code>AutoCompleteTextView searchStores;
  String[] searchStoresString; 
  ArrayAdapter&lt;String&gt; searchStoresAdapter;
  
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.stores);
  
      findviews();
      autocomplete();
  
      searchStores.setOnItemClickListener(this);
  }
  
  public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long id)
  { 
      String str = (String) adapterView.getItemAtPosition(position);
      Toast.makeText(this, str + " selected", Toast.LENGTH_SHORT).show();
  }
  
  private void findviews()
  {
      searchStores = (AutoCompleteTextView) findViewById(R.id.autocomplete_stores);
  }
  
  private void autocomplete()
  {
      searchStoresString = getResources().getStringArray(R.array.stores_array);
      searchStoresAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, searchStoresString);
  
      searchStores.setThreshold(1); 
      searchStores.setAdapter(searchStoresAdapter);
  }
  </code></pre>
  
  <p>Everything is working fine. Thanks in advice.</p>