【发布时间】:2012-12-30 14:15:13
【问题描述】:
是否可以将在newView(..) 期间创建的一个 视图添加为单独的类型,以便在bindView(...) 期间防止重复使用该视图?
这是我的自定义 cursorAdapter 的样子:
@Override
public void bindView(View vi, Context arg1, Cursor cursor) {
priority.setText(cursor.getString(cursor.getColumnIndex(TodoTable.COLUMN_PRIORITY)));TextView timeElapsed = (TextView)vi.findViewById(R.id.todayTime); //time
long id = cursor.getLong(cursor.getColumnIndex(TodoTable.COLUMN_ID));
if(ts.getRunning() == id){
ts.startTimer(vi, ts.getCurrentTaskStart(), id);
}else{
long time = cursor.getLong((cursor.getColumnIndex(TodoTable.COLUMN_TIME)));
timeElapsed.setText(ts.getTimeString(0, 0, time));
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup arg2) {
LayoutInflater inflater = LayoutInflater.from(context);
View vi = inflater.inflate(R.layout.list_item, null);
bindView(vi, context, cursor);
return vi;
}
我尝试使用 getItemViewType 和 getViewTypeCount 将其添加到不同的类型,但这只能处理位置,而不是与列表视图的行关联的 ID。
我想防止在创建时使用ts.getRunning() == id 的视图在我滚动时在其他位置重复使用。我该怎么做这样的事情?
【问题讨论】:
标签: android listview android-cursoradapter