新しいデータを取得してフィルタリングする AutoCompleteTextView のカスタム performFiltering があります。
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (null != constraint && constraint.length() >= 2) {
ArrayList<Destination> temporaryDestination = updateArray();
filterResults.count = temporaryDestination.size();
filterResults.values = temporaryDestination;
return filterResults;
} else {
if (destinations != null) {
filterResults.count = destinations.size();
filterResults.values = destinations;
}
return filterResults;
}
}
多くの宛先を取得する 2 文字を入力して下にスクロールすると、FC と次のスタック トレースが表示されます。
06-22 14:44:07.756: ERROR/AndroidRuntime(2188): FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.AbsListView$LayoutParams
at android.widget.AutoCompleteTextView.buildDropDown(AutoCompleteTextView.java:1350)
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1140)
at android.widget.AutoCompleteTextView.onKeyDown(AutoCompleteTextView.java:714)
at android.view.KeyEvent.dispatch(KeyEvent.java:1256)
at android.view.View.dispatchKeyEvent(View.java:3855)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
最大 5 つの結果を返す場合、正常に動作します (以下を追加するだけです)。
if (null != constraint && constraint.length() >= 2) {
ArrayList<Destination> temporaryDestination = updateArray();
if (temporaryDestination.size()>5) {
temporaryDestination = new ArrayList<Destination>(temporaryDestination.subList(0, 5));
}
filterResults.count = temporaryDestination.size();
filterResults.values = temporaryDestination;
次のことを行うAutoCompleteTextViewの1350行目のAndroidソースコードで、エラーを次のように追跡しました。
if (view != null) {
LinearLayout.LayoutParams hintParams =
(LinearLayout.LayoutParams) view.getLayoutParams();
otherHeights = view.getMeasuredHeight() + hintParams.topMargin
+ hintParams.bottomMargin;
}
}
ただし、結果が 5 を超えてスクロールを開始したときに、このコードが間違ったクラスを受け取る理由がわかりません。結果を 5 に制限する解決策は、本当の問題がまだ残っていると感じているため、醜いです。誰にも提案はありますか?
オートコンプリート アイテムの xml レイアウトを次に示します (ただし、カスタム ドロップダウンの実装はありません)。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#000">
</TextView>
</RelativeLayout>