class
WeiboListAdapter
extends
BaseAdapter
{
private
final
static
int
VIEW_TYPE1 =
0
;
private
final
static
int
VIEW_TYPE2 =
1
;
private
final
static
int
VIEW_TYPE_COUNT = VIEW_TYPE2 +
1
;
@Override
public
View getView(
int
position, View convertView, ViewGroup parent)
{
CommentViewHolder commentHolder =
null
;
ViewHolder holder =
null
;
int
type = getItemViewType(position);
if
(convertView ==
null
)
{
if
(type == VIEW_TYPE1)
{
convertView = getLayoutInflater().inflate(R.layout.weibo_item,
null
);
holder =
new
ViewHolder();
holder.headerImg = (ImageView) convertView.findViewById(R.id.weibo_item_iv_headerImg);
holder.userName = (TextView) convertView.findViewById(R.id.weibo_item_tv_userName);
holder.commentNum = (TextView) convertView.findViewById(R.id.weibo_item_tv_commentNum);
holder.forwardTimes = (TextView) convertView.findViewById(R.id.weibo_item_tv_forwardTimes);
holder.content = (TextView) convertView.findViewById(R.id.weibo_item_tv_content);
holder.contentImg = (ImageView) convertView.findViewById(R.id.weibo_item_iv_contentImg);
holder.forwardContent = (TextView) convertView.findViewById(R.id.weibo_item_tv_forwardContent);
holder.forwardContentImg = (ImageView) convertView.findViewById(R.id.weibo_item_iv_forwardContentImg);
holder.from = (TextView) convertView.findViewById(R.id.weibo_item_tv_from);
holder.time = (TextView) convertView.findViewById(R.id.weibo_item_tv_time);
holder.retweetedLayout = convertView.findViewById(R.id.weibo_item_retweetedLayout);
convertView.setTag(holder);
}
else
{
commentHolder =
new
CommentViewHolder();
convertView = getLayoutInflater().inflate(R.layout.weibocomment_item,
null
);
commentHolder.headerImg = (ImageView) convertView.findViewById(R.id.weibocomment_item_iv_headerImg);
commentHolder.userName = (TextView) convertView.findViewById(R.id.weibocomment_item_tv_userName);
commentHolder.time = (TextView) convertView.findViewById(R.id.weibocomment_item_tv_time);
commentHolder.content = (TextView) convertView.findViewById(R.id.weibocomment_item_tv_content);
convertView.setTag(commentHolder);
}
}
else
{
if
(type == VIEW_TYPE1)
{
holder = (ViewHolder) convertView.getTag();
}
else
{
commentHolder = (CommentViewHolder) convertView.getTag();
}
}
WeiboJson weiboJson = mDataList.get(position);
if
(type == VIEW_TYPE1)
{
updataWeiboData(holder, weiboJson);
}
else
{
updateCommentData(commentHolder, weiboJson);
}
return
convertView;
}
@Override
public
int
getCount()
{
return
mDataList.size();
}
@Override
public
int
getItemViewType(
int
position)
{
if
(position ==
0
)
{
return
VIEW_TYPE1;
}
else
{
return
VIEW_TYPE2;
}
}
@Override
public
int
getViewTypeCount()
{
return
VIEW_TYPE_COUNT;
}
@Override
public
Object getItem(
int
position)
{
return
mDataList.get(position);
}
@Override
public
long
getItemId(
int
position)
{
return
position;
}
}