我有一个从AutoCompleteTextView
延伸的customAdapter,我有一个问题需要显示建议,我认为这是" performFiltering
"但我不太清楚。
这是我的代码适配器:
我做错了什么?
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AutoCompleteTextView;
public class InstantAutoComplete extends AutoCompleteTextView {
Context context;
public InstantAutoComplete(Context context) {
super(context);
context = 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;
}
private boolean mIsKeyboardVisible;
@Override
protected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (getWindowVisibility() == View.GONE) {
Log.d("InstantAutoComplete", "Window not visible, will not show drop down");
return;
}
if (focused) {
/*try {*/
performFiltering(getText(), 0);
/*}catch (Exception e){
Toast.makeText(context,"Click",Toast.LENGTH_SHORT).show();
}*/
}
mIsKeyboardVisible = focused;
}
/*@Override
public View getRootView() {
return super.getRootView();
}*/
/*@Override
protected void performFiltering(final CharSequence text, final int keyCode) {
String filterText = "";
super.performFiltering(filterText, keyCode);
}*/
我放了一张图片: Image
如果我使用" AutoCompleteTextView"工作正常,但如果使用"自定义不起作用"
答案 0 :(得分:0)
解决方案:
使用默认的ArrayAdapter。我的自定义适配器出错了。