I'm trying to set an AutoCompleteTextView as a ListView header, but if I do so the autocomplete box never appears. The code for creating the auto complete view comes directly from the Hello, AutoComplete tutorial in googles docs. The COUNTRIES array also comes from there.
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView myList = (ListView) findViewById(R.id.ResultList);
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
TableLayout searchHeader = (TableLayout) layoutInflater.inflate(R.layout.search_header, null);
myList.addHeaderView(searchHeader, null, false);
final AutoCompleteTextView textView = (AutoCompleteTextView) myList.findViewById(R.id.edit);
ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
textView.setAdapter(searchAdapter);
textView.setThreshold(1);
//Dummy data for listview.
String[] listContent = {
"test", "test", "test", "test",
"test", "test", "test", "test"
};
ArrayAdapter<String> adapter = new SearchResultAdapter(this, listContent);
myList.setAdapter(adapter);
}
As a test, I added a TextChangedListener to try and force show the dialog
textView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
textView.showDropDown();
}
});
The dialog appears but is closed almost instantly. I wonder if some kind of event bubbling from the list view is causing this?