我有一个ListView
适配器,根据行项目的类型设置不同的布局。回收具有不同行布局的ListView行
如果我使用一个持有人回收我的行,如下面的代码所示,我想我会得到一些错误,因为对于一个循环的行,我会得到最新的非循环行的布局,这可能不会属于同一类型。
我应该避免在这种情况下回收行吗?我还有什么其他选择?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MyHolder holder = null;
int type = getItemViewType(position);
if(row == null)
{
holder = new MyHolder();
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
if(type == TYPE_1){
row = inflater.inflate(R.layout.layout_type_1, parent, false);
}
else if(type == TYPE_2){
row = inflater.inflate(R.layout.layout_type_2, parent, false);
}
else {
row = inflater.inflate(R.layout.layout_type_3, parent, false);
}
row.setTag(holder);
}
else
{
holder = (MyHolder)row.getTag();
}
/* ... */
}
你是否重写getViewTypeCount和getItemViewType? – jimmithy 2013-03-04 16:16:20
@jimmithy:是的,我做 – jul 2013-03-04 16:18:45
回收RecyclerView和多行布局示例演示http://code2concept.blogspot.in/2015/10/android-multiple-row-layout-using.html回收处理回收站本身 – nitesh 2015-10-15 05:26:59