AutocompleteTextView(建议不正确)
AutocompleteTextView (Suggestions incorrect)
我有一个从 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" 可以正常工作,但如果使用 "custom not works"
解决方案:
使用默认的 ArrayAdapter。我在使用自定义适配器时遇到错误。
我有一个从 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" 可以正常工作,但如果使用 "custom not works"
解决方案:
使用默认的 ArrayAdapter。我在使用自定义适配器时遇到错误。