Reputation: 1057
I ran into an issue. I have a bus arrival app with several color-coded bus buttons that if clicked, a drop down menu will be displayed from an AutoCompleteTextView according to the button clicked. However, I also want to have a default drop down menu for the AutoCompleteTextView so that if I clicked on one of the buttons without selecting the listed item, the adapter automatically reverts back to the default adapter. After the parameter is selected, a submit button can be clicked to submit for the result. I am resetting the adapter at onClickListener of the submit button, but this does not allow for resetting adapter after clicking on the color-coded bus button without selecting. So how (or where) should I reset the default adapter?
This is my inherited AutoCompleteTextView class:
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
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);
Log.d("IAC", "entered onFocusChanged");
/*if (focused) {
Log.d("IAC", "focused, text="+getText());
performFiltering(getText(), 0);
Log.d("IAC", "after performFiltering");
showDropDown();
} */
}
}
This is my default drop down list inherited from AutoCompleteTextView
This is my cursor on one of the color-coded bus button
This is the drop down list from clicking the above button
P.S. I guess I need to reset the default adapter after the color-coded bus button loses its focus. How do I do that?
Upvotes: 1
Views: 624
Reputation: 1057
I got it!
button.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// code to execute when button loses focus
}
}
});
Thanks to everyone that posted. :)
Upvotes: 1