关于convertView复用的问题

解析数据一共有两种,有一种带图片有一种不带图片,故用了两套布局,流程和正常ListView加载多套布局一样复用convertView然后setTag,但是一运行就会出错,详见下面:

Adapter中getView方法代码如下:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = list.get(position).getType();
ViewHolder3 vh3 = null;
ViewHolder vh = null;
Picasso p = Picasso.with(context);
if (convertView == null) {
switch (type) {
case 0:
convertView = LayoutInflater.from(context).inflate(R.layout.item_social_lv_noimage, null);
vh = new ViewHolder();
vh.iv_head = (ImageView) convertView.findViewById(R.id.iv_item_no_head);
vh.tv_name = (TextView) convertView.findViewById(R.id.tv_item_no_name);
vh.tv_date = (TextView) convertView.findViewById(R.id.tv_item_no_date);
vh.tv_detail = (TextView) convertView.findViewById(R.id.tv_item_no_detail);
vh.tv_theme = (TextView) convertView.findViewById(R.id.tv_item_no_theme);
vh.tv_eye = (TextView) convertView.findViewById(R.id.tv_item_no_eye);
vh.tv_comments = (TextView) convertView.findViewById(R.id.tv_item_no_comments);
vh.tv_good = (TextView) convertView.findViewById(R.id.tv_item_no_good);
convertView.setTag(vh);
break;
case 1:
convertView = LayoutInflater.from(context).inflate(R.layout.item_social_lv_oneimage, null);
vh3 = new ViewHolder3();
vh3.iv_head = (ImageView) convertView.findViewById(R.id.iv_item_one_head);
vh3.iv_main1 = (ImageView) convertView.findViewById(R.id.iv_item_one_main);
vh3.tv_name = (TextView) convertView.findViewById(R.id.tv_item_one_name);
vh3.tv_date = (TextView) convertView.findViewById(R.id.tv_item_one_date);
vh3.tv_detail = (TextView) convertView.findViewById(R.id.tv_item_one_detail);
vh3.tv_theme = (TextView) convertView.findViewById(R.id.tv_item_one_theme);
vh3.tv_eye = (TextView) convertView.findViewById(R.id.tv_item_one_eye);
vh3.tv_comments = (TextView) convertView.findViewById(R.id.tv_item_one_comments);
vh3.tv_good = (TextView) convertView.findViewById(R.id.tv_item_one_good);
convertView.setTag(vh3);
break;
default:
break;
}
} else {
switch (type) {
case 0:
vh = (ViewHolder) convertView.getTag();
break;
case 1:
vh3 = (ViewHolder3) convertView.getTag();
break;
default:
break;
}
}
switch (type) {
case 0:
CommentBean comm = (CommentBean) list.get(position);
vh.tv_name.setText(comm.getAccountName());
String time = comm.getUserTime().replace("T", " ");
vh.tv_date.setText(time);
vh.tv_detail.setText(comm.getContent());
String theme = comm.getTitle();
vh.tv_theme.setText("#" + theme);
vh.tv_eye.setText(comm.getClickCount());
vh.tv_comments.setText(comm.getReplyCount());
vh.tv_good.setText(comm.getFavourableCount());
String img_head = comm.getIconPath();
p.load(img_head).error(R.mipmap.ic_launcher).into(vh.iv_head);
break;
case 1:
CommentBean3 comm3 = (CommentBean3) list.get(position);
vh3.tv_name.setText(comm3.getAccountName());
String time3 = comm3.getUserTime().replace("T", " ");
vh3.tv_date.setText(time3);
vh3.tv_detail.setText(comm3.getContent());
String theme3 = comm3.getTitle();
vh3.tv_theme.setText("#" + theme3);
vh3.tv_eye.setText(comm3.getClickCount());
vh3.tv_comments.setText(comm3.getReplyCount());
vh3.tv_good.setText(comm3.getFavourableCount());
String img_head3 = comm3.getIconPath();
p.load(img_head3).error(R.mipmap.ic_launcher).into(vh3.iv_head);
break;
default:
break;
}

return convertView;

}

然而报错
代码:
Process: com.ok.starfinder, PID: 9121
java.lang.ClassCastException: com.ok.starfinder.adapter.SquareListAdapter$ViewHolder3 cannot be cast to com.ok.starfinder.adapter.SquareListAdapter$ViewHolder
at com.ok.starfinder.adapter.SquareListAdapter.getView(SquareListAdapter.java:124)
at android.widget.AbsListView.obtainView(AbsListView.java:2240)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1940)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1137)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1319)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1024)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5694)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

希望有大神解决一下,急

java.lang.ClassCastException: com.ok.starfinder.adapter.SquareListAdapter$ViewHolder3 cannot be cast to com.ok.starfinder.adapter.SquareListAdapter$ViewHolder
at com.ok.starfinder.adapter.SquareListAdapter.getView(SquareListAdapter.java:124)
你看看124行有啥问题,看错误提示是类型转换出错了。