title: Dynamic AutoCompleteTextView Suggestions Disappearing
body: <p>So I had it working... and then it broke, and I don't know why. I've been pulling my hair out trying to figure out what's gone wrong.</p>
  
  <p>Here is the structure of the code:</p>
  
  <pre><code>locale = (AutoCompleteTextView) findViewById(locationText);
  locale.setThreshold(3);
  adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, locationSuggestions);
  adapter.setNotifyOnChange(true);
  locale.setAdapter(adapter);
  
  locale.addTextChangedListener(new TextWatcher(){
  
      @Override
      public void afterTextChanged(Editable s) {
  
      }
          @Override
      public void beforeTextChanged(CharSequence s, int start, int count,
              int after) {    
      }
          @Override
      public void onTextChanged(CharSequence s, int start, int before,
              int count) {
          if(!s.toString().contains(","))
          {
              String loc = s.toString().replace(" ", "%20");
              new JsonTask(loc).execute();
                  adapter.notifyDataSetChanged();
              locale.setAdapter(adapter);     
          }   
      }       
  });
  </code></pre>
  
  <p>I'm just at a total loss as to what to do. I started off from this tutorial here:</p>
  
  <p><a href="http://www.gaanza.com/blog/android-autocompletetextview-mysql/" rel="nofollow">http://www.gaanza.com/blog/android-autocompletetextview-mysql/</a></p>
  
  <p>I tried doing this with his custom AutoCompleteTextView class, but something to do with the way he was filtering results just didn't work.</p>
  
  <p>Here's the thing: my JsonTask appropriately updates my String[] locationSuggestions. The data is there. The textbox is filled with an initial location pulled from a geocoder earlier in the code. When you erase the suggestion, nothing pops up until you go under the threshold and then type up to 3 characters. On the third character, the drop down appears for a split second and then disappears. If you continue to type it does not show up again. If you erase the string and then enter a new set of characters, the drop down will pop up briefly again and then disappear.</p>
  
  <p>I honestly can't remember what I changed that broke it. It was working fine, and then I went to edit some of the layout and it stopped working. I changed the layout back and even still, nothing. This is what my xml looks like:</p>
  
  <pre><code>&lt;AutoCompleteTextView
          android:id="@+id/locationText"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:layout_column="0"
          android:layout_columnSpan="3"
          android:layout_gravity="fill_horizontal|center_vertical"
          android:layout_margin="10dp"
          android:layout_marginBottom="40dp"
          android:layout_row="2"
          android:drawableLeft="@drawable/locationicon"
          android:ems="10"
          android:imeActionLabel="actionGo"
          android:singleLine="true" &gt;
  
      &lt;/AutoCompleteTextView&gt;
  </code></pre>
  
  <p>And for completeness' sake, here is my AsyncTask:</p>
  
  <pre><code>public class JsonTask extends AsyncTask{
  
  private String query;
  @Override
  protected Void doInBackground(Object... arg0) {
  
      JSONParser jsonParser = new JSONParser();
  
      JSONArray array;
      try {
          array=jsonParser.getJSONFromUrl(url + query);
  
          JSONObject citystate = new JSONObject();
  
          String city;
          String state;
  
          for(int i = 0; i&lt;5; i++)
          {
              citystate = array.getJSONObject(i);
              state = citystate.getString("State");
              city = citystate.getString("City");
              locationSuggestions[i] = city + ", " + state;
          }
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();}
  
      return null;
  }   
  public JsonTask(String text)
  {
      query = text;
  }
  }
  </code></pre>