我遇到了一个问题。我有一个带有几个彩色编码总线按钮的总线到达应用程序,如果点击,将根据点击的按钮从AutoCompleteTextView显示一个下拉菜单。但是,我还想要一个AutoCompleteTextView的默认下拉菜单,这样如果我单击其中一个按钮而不选择列出的项目,则适配器会自动恢复为默认适配器。选择参数后,可以单击提交按钮以提交结果。我正在重置提交按钮的onClickListener上的适配器,但这不允许在没有选择的情况下单击颜色编码的总线按钮后重置适配器。那么我应该如何(或在哪里)重置默认适配器?
这是我继承的AutoCompleteTextView类:
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();
} */
}
}
这是我从AutoCompleteTextView继承的默认下拉列表
这是我在其中一个彩色编码总线按钮上的光标
这是点击上面的按钮
的下拉列表
P.S。我猜我需要在颜色编码的总线按钮失去焦点后重置默认适配器。我该怎么做?
答案 0 :(得分:1)
我明白了!
button.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// code to execute when button loses focus
}
}
});
感谢发布的所有人。 :)