Created
September 7, 2015 12:36
-
-
Save ruuhkis/d942330d97163d868ee7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use it, please?