我真的需要你的帮助。我在ListView中有一个带有项目和类别分隔符的ArrayAdapter。滚动时,顺序混乱,似乎还有其他问题。您能否就我的代码向我提供帮助,建议或意见?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
int type = getItemViewType(position);
holder = null;
Watch = (Watch)filtered.get(position);
if (v == null) {
holder = new ViewHolder();
switch (type) {
case Watch .TYPE_WATCH :
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
break;
case Watch.TYPE_SEPARATOR :
LayoutInflater vi2 = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = vi2.inflate(R.layout.list_header, null);
break;
}
} else {
holder = (ViewHolder)v.getTag();
}
switch (type) {
case Watch.TYPE_CARD :
if (o != null) {
holder.textView1 = (TextView)v.findViewById(R.id.toptext);
holder.textView2 = (TextView)v.findViewById(R.id.bottomtext);
if (holder.textView1 != null)
holder.textView1.setText(o.getName());
if (holder.textView2 != null)
holder.textView2.setText(o.getPosition());
}
break;
case Watch.TYPE_SEPARATOR :
if (o != null) {
holder.SeparatorTextView = (TextView)v.findViewById(R.id.list_header_title);
if(holder.SeparatorTextView != null)
holder.SeparatorTextView.setText(o.getName());
}
break;
}
v.setTag(holder);
return v;
}
我还覆盖了getItemViewType和getViewTypeCount,是否需要显示?它们是否必要?各种帮助将不胜感激!我已经坚持了一段时间了!