prevent再利用的ListView的一些观点(自定义光标适配器) [英] Prevent re-use of some views in ListView (custom cursor-adapter)
问题描述
是否有可能增加一个在 NewView的创建的视图(..)
作为一个单独的类型,所以只是认为重用在 pvented $ P $ bindView(...)
?
Is it possible to add one view created during newView(..)
as a separate type, so that reuse of just that view is prevented during bindView(...)
?
这是我自定义的CursorAdapter是这样的:
This is what my custom cursorAdapter looks like:
@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与ListView的行相关联。
I tried adding it to a different type, using getItemViewType
and getViewTypeCount
but that can only deals with positions and not the IDs associated with the rows of the listview.
我想prevent与视图ts.getRunning()== ID
在创建重复使用在其他位置,当我滚动的时间。我怎么会做这样的事情?
I want to prevent the view with ts.getRunning() == id
at the time of creation being reused at other positions when I scroll. How would I do something like this?
推荐答案
如果你想prevent来看重用在一定的位置上做以下
If you want to prevent the reuse of view at a certain position the do the following
@Override
public int getItemViewType(int position) {
mCursor.moveToPosition(position);
if (mCursor.getLong(mCursor.getColumnIndex(TodoTable.COLUMN_ID)) == ts.getRunning()){
return IGNORE_ITEM_VIEW_TYPE;
}
return super.getItemViewType(position);
}
如果您返回 IGNORE_ITEM_VIEW_TYPE
在 getItemViewType(位置)
则认为在该位置将不会被回收。有关更多信息 IGNORE_ITEM_VIEW_TYPE
是的这里
If you return IGNORE_ITEM_VIEW_TYPE
in getItemViewType(position)
then the view at that position will not be recycled. More info about IGNORE_ITEM_VIEW_TYPE
is here
这篇关于prevent再利用的ListView的一些观点(自定义光标适配器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!