View obtainView(int position, boolean[] isScrap) {
isScrap[0] = false;
View scrapView;
//从回收器中获取view
scrapView = mRecycler.getScrapView(position);
View child;
if (scrapView != null) {
...
//若不为空,则传入convertView,这样的话重用了view,同时更新了数据
child = mAdapter.getView(position, scrapView, this);
...
} else {
//若为空,则在getView中重新创建HolderView,且填入数据
child = mAdapter.getView(position, null, this);
...
}
return child;
}
/**
* Gets the data associated with the specified position in the list.
*
* @param position Which data to get
* @return The data associated with the specified position in the list
*/
public Object getItemAtPosition(int position) {
T adapter = getAdapter();
return (adapter == null || position < 0) ? null : adapter.getItem(position);
}
/**
* @return The data corresponding to the currently selected item, or
* null if there is nothing selected.
*/
public Object getSelectedItem() {
T adapter = getAdapter();
int selection = getSelectedItemPosition();
if (adapter != null && adapter.getCount() > 0 && selection >= 0) {
return adapter.getItem(selection);
} else {
return null;
}
}
public long getItemIdAtPosition(int position) {
T adapter = getAdapter();
return (adapter == null || position < 0) ? INVALID_ROW_ID : adapter.getItemId(position);
}
private void fireOnSelected() {
if (mOnItemSelectedListener == null)
return;
int selection = this.getSelectedItemPosition();
if (selection >= 0) {
View v = getSelectedView();
//这里调用的getItemId得到的返回值与selection都属于同一个item的特征,其意义也就在于在选择接口的onItemSelected方法中可
//以直接拿到该item的id,而不需要通过获取adapter来间接实现
mOnItemSelectedListener.onItemSelected(this, v, selection,
getAdapter().getItemId(selection));
} else {
mOnItemSelectedListener.onNothingSelected(this);
}
}
int findSyncPosition() {
...
rowId = adapter.getItemId(seed);
if (rowId == idToMatch) { //从这里来看,getItemId似乎应该对于不同的item返回不同的值,保持唯一性
// Found it!
return seed;
}
...
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有