Skip to content

Instantly share code, notes, and snippets.

@ruuhkis
Created September 7, 2015 12:36
Show Gist options
  • Save ruuhkis/d942330d97163d868ee7 to your computer and use it in GitHub Desktop.
Save ruuhkis/d942330d97163d868ee7 to your computer and use it in GitHub Desktop.
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AutoCompleteTextView;
/**
* Created by PasiMatalamaki on 7.9.2015.
*/
public class InstantAutoCompleteTextView extends AutoCompleteTextView {
private boolean showAlways;
public InstantAutoCompleteTextView(Context context) {
super(context);
}
public InstantAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public InstantAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public InstantAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void setShowAlways(boolean showAlways) {
this.showAlways = showAlways;
}
@Override
public boolean enoughToFilter() {
return showAlways || super.enoughToFilter();
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
showDropDownIfFocused();
}
private void showDropDownIfFocused() {
if (enoughToFilter() && isFocused() && getWindowVisibility() == View.VISIBLE) {
showDropDown();
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
showDropDownIfFocused();
}
}
@GyyBest
Copy link

GyyBest commented May 31, 2017

How to use it, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment