【发布时间】:2014-01-02 19:22:16
【问题描述】:
我有一个问题,在搜索 SO 和 Google 后我找不到答案。在 Android 中使用适配器时,通过在 getView() 方法中使用 convertView 参数来重用列表项视图是一种很好的做法。我的问题是,如果我对convertView 进行更改,这种更改是否会持续到将来对getView() 的调用中?
例如:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
ViewHolder holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.list_item, null);
convertView.setTag(holder);
// if i call this method here, will all future views passed into convertView
// also have this set??
// From what I know about Java and objects I would guess yes
// but I'm not 100% sure how Android processes the convertView behind the scenes
((ViewGroup) convertView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
}
ViewHolder holder = (ViewHolder) convertView.getTag();
// currently setDescendantFocusability is called here,
// I want to move it to where it above to help improve performance
return convertView;
}
【问题讨论】:
-
我在某处听说您应该将 convertView 用作只读。可能在这里youtube.com/watch?v=wDBM6wVEO70
标签: android performance android-adapter