Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@GyyBest

GyyBest May 31, 2017

How to use it, please?

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