我想扩展 SimpleCursorAdapter,为方法添加} else if (c instanceof MyView) { setMyViewMyThing(MyView v, text)
一个bindView
。
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");
}
}
}
}
}
和是 SimpleCursorAdpater 的私有成员这一事实阻止了我这样mViewBinder
做。mTo
mFrom
有没有比将SimpleCursorAdapter
批发源复制到 aMyCursorView
并将我的条件添加到更好的方法来实现我的目标bindView
?(该解决方案会奏效,而且会很快,但有不良做法的味道。)
(在元级别上,Android 作者似乎已经用我扩展 SimpleCursorAdapter 的自由来换取他们更改实现的自由。有没有可以同时保留两者的语言?)