我想延長SimpleCursorAdapter,涉及一種} else if (c instanceof MyView) { setMyViewMyThing(MyView v, text)
添加到bindView
方法。如何擴展Android的SimpleCursorAdapter?
public void bindView(View view, Context context, Cursor cursor) {
final ViewBinder binder = mViewBinder;
final int count = mTo.length;
final int[] from = mFrom;
final int[] to = mTo;
for (int i = 0; i < count; i++) {
final View v = view.findViewById(to[i]);
if (v != null) {
boolean bound = false;
if (binder != null) {
bound = binder.setViewValue(v, cursor, from[i]);
}
if (!bound) {
String text = cursor.getString(from[i]);
if (text == null) {
text = "";
}
if (v instanceof TextView) {
setViewText((TextView) v, text);
} else if (v instanceof ImageView) {
setViewImage((ImageView) v, text);
} else {
throw new IllegalStateException(v.getClass().getName() + " is not a " +
" view that can be bounds by this SimpleCursorAdapter");
}
}
}
}
}
事實上,mViewBinder
,mTo
和mFrom
是SimpleCursorAdpater的私有成員阻止我這樣做。
有沒有更好的方法來實現我的目標,而不是將SimpleCursorAdapter
批發的來源複製到MyCursorView
並將我的條件添加到bindView
? (這個解決方案可以工作,並且速度很快,但是會很糟糕的做法。)
(在一個元級別上,它看起來像Android作者交易了我自由地擴展SimpleCursorAdapter,以便他們改變實現的自由。有沒有可以既保留任何語言?)
不應該設置自定義聯編程序嗎? – njzk2