Android: AutoCompleteTextView show suggestions when no text entered
This is documented behavior:
When
threshold
is less than or equals 0, a threshold of 1 is applied.
You can manually show the drop-down via showDropDown()
, so perhaps you can arrange to show it when you want. Or, subclass AutoCompleteTextView
and override enoughToFilter()
, returning true
all of time.
Easiest way:
Just use setOnTouchListener and showDropDown()
AutoCompleteTextView text;
.....
.....
text.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
text.showDropDown();
return false;
}
});
Here is my class InstantAutoComplete. It's something between AutoCompleteTextView
and Spinner
.
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.AutoCompleteTextView;
public class InstantAutoComplete extends AutoCompleteTextView {
public InstantAutoComplete(Context context) {
super(context);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1, int arg2) {
super(arg0, arg1, arg2);
}
@Override
public boolean enoughToFilter() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (focused && getAdapter() != null) {
performFiltering(getText(), 0);
}
}
}
Use it in your xml like this:
<your.namespace.InstantAutoComplete ... />