use of org.qii.weiciyuan.support.lib.ListViewMiddleMsgLoadingView in project weiciyuan by qii.
the class AbstractAppListAdapter method getView.
/**
* use getTag(int) and setTag(int, final Object) to solve getItemViewType(int) bug.
* When you use getItemViewType(int),getTag(),setTag() together, if getItemViewType(int) change
* because
* network switch to use another layout when you are scrolling listview, bug appears,the other
* listviews in other tabs
* (Actionbar tab navigation) will mix several layout up, for example, the correct layout
* should
* be TYPE_NORMAL_BIG_PIC,
* but in the listview, you can see some row's layouts are TYPE_NORMAL, some are
* TYPE_NORMAL_BIG_PIC. if you print
* getItemViewType(int) value to the console,their are same type
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
PrefView prefView = null;
int itemViewType = getItemViewType(position);
if (convertView == null || convertView.getTag(R.drawable.ic_launcher + itemViewType) == null) {
View view = null;
switch(itemViewType) {
case TYPE_SIMPLE:
view = initSimpleLayout(parent);
break;
case TYPE_MIDDLE:
view = initMiddleLayout(parent);
break;
case TYPE_NORMAL:
prefView = prefNormalViews.poll();
if (prefView != null) {
view = prefView.view;
}
if (view == null) {
view = initNormalLayout(parent);
}
break;
case TYPE_NORMAL_BIG_PIC:
prefView = prefBigPicViews.poll();
if (prefView != null) {
view = prefView.view;
}
if (view == null) {
view = initBigPicLayout(parent);
}
break;
default:
view = initNormalLayout(parent);
break;
}
convertView = view;
if (itemViewType != TYPE_MIDDLE) {
if (prefView == null) {
holder = buildHolder(convertView);
} else {
holder = prefView.holder;
}
convertView.setTag(R.drawable.ic_launcher + getItemViewType(position), holder);
convertView.setTag(R.string.listview_index_tag, R.drawable.ic_launcher + getItemViewType(position));
tagIndexList.add(R.drawable.ic_launcher + getItemViewType(position));
}
} else {
holder = (ViewHolder) convertView.getTag(R.drawable.ic_launcher + getItemViewType(position));
}
if (itemViewType != TYPE_MIDDLE) {
configLayerType(holder);
configViewFont(holder);
bindViewData(holder, position);
bindOnTouchListener(holder);
} else {
if (savedCurrentMiddleLoadingViewPosition == position + listView.getHeaderViewsCount()) {
ListViewMiddleMsgLoadingView loadingView = (ListViewMiddleMsgLoadingView) convertView;
loadingView.load();
}
}
return convertView;
}
Aggregations