ツッコミ--ExpandableListView
2438 ワード
ExpandableListViewのアダプタ(BaseExpandableListAdapterから継承)をAutoCompleteTextViewに同時にバインドし、検索フィルタ機能を実現する必要があります.インタフェースFilterableを実現し、コンパイルが間違っている以上、成功を目前にしていると考えています.
MyExpandableListAdapterはListAdapterを実装していません.BaseExpandableListAdapterが最終的に継承したインタフェースExpandableListAdapterにフォローします.ListAdapterのサブクラスではない以上!ExpandableListViewはListView googleから継承されています.異なるアダプタを実現させる以上、ああ!犬の糞!
setAdapterに2つのリロードがあるのを見てみましょう
呼び出した場合
直接異常を投げる.別の関数の実装を見てみましょう
ほら、googleはExpandableListAdapterとListAdapterで直接リンクを作ってListViewに適している以上.
ExpandableListViewのこの実装方法はlistviewを再利用できるが,関数setAdapter署名と親ListViewが統一されておらず,呼び出し者にトラップを追加し複雑さを増加させるに違いない.
上の質問に戻ります:MyExpandableListAdapterが同時にAutoCompleteTextViewでadapterを作る必要がある場合は、おとなしくListAdapterを実現するしかないので、ListAdapter、ExpandableListAdapterの2つのインタフェースを実現します.このようにコンパイルすることはできません.
スマートなjavaコンパイラはMyExpandableListAdapterをListAdapterのサブクラスと見なしています.どうしよう?簡単です!小さなテクニックでコンパイラをより賢くする
これでMyExpandableListAdapterはExpandableListViewのみならずAutoCompleteTextViewにも利用できるようになりました.
この文章があなたに役に立つことを望みます!
The generic method setAdapter(T) of type AutoCompleteTextView is not applicable for the arguments (MyExpandableListAdapter). The inferred type MyExpandableListAdapter is not a valid substitute for the bounded parameter <T extends ListAdapter & Filterable>
MyExpandableListAdapterはListAdapterを実装していません.BaseExpandableListAdapterが最終的に継承したインタフェースExpandableListAdapterにフォローします.ListAdapterのサブクラスではない以上!ExpandableListViewはListView googleから継承されています.異なるアダプタを実現させる以上、ああ!犬の糞!
setAdapterに2つのリロードがあるのを見てみましょう
public void setAdapter(ExpandableListAdapter adapter)
public void setAdapter(ListAdapter adapter)
呼び出した場合
public void setAdapter(ListAdapter adapter)
直接異常を投げる.別の関数の実装を見てみましょう
public void setAdapter(ExpandableListAdapter adapter) {
// Set member variable
mAdapter = adapter;
if (adapter != null) {
// Create the connector
mConnector = new ExpandableListConnector(adapter);
} else {
mConnector = null;
}
// Link the ListView (superclass) to the expandable list data through the connector
super.setAdapter(mConnector);
}
ほら、googleはExpandableListAdapterとListAdapterで直接リンクを作ってListViewに適している以上.
ExpandableListViewのこの実装方法はlistviewを再利用できるが,関数setAdapter署名と親ListViewが統一されておらず,呼び出し者にトラップを追加し複雑さを増加させるに違いない.
上の質問に戻ります:MyExpandableListAdapterが同時にAutoCompleteTextViewでadapterを作る必要がある場合は、おとなしくListAdapterを実現するしかないので、ListAdapter、ExpandableListAdapterの2つのインタフェースを実現します.このようにコンパイルすることはできません.
For ExpandableListView, use setAdapter(ExpandableListAdapter) instead of " +
"setAdapter(ListAdapter)
スマートなjavaコンパイラはMyExpandableListAdapterをListAdapterのサブクラスと見なしています.どうしよう?簡単です!小さなテクニックでコンパイラをより賢くする
expandableListView.setAdapter((ExpandableListAdapter)MyExpandableListAdapter);
これでMyExpandableListAdapterはExpandableListViewのみならずAutoCompleteTextViewにも利用できるようになりました.
この文章があなたに役に立つことを望みます!