@Override public View getView(int position, View convertView, ViewGroup parent) { Data_DB_News news = mNewsList.get(position); ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.item_news, parent, false); holder = new ViewHolder(); holder.Tv_NewsTitle = (TextView) convertView.findViewById(R.id.item_news_title); holder.Image = (SimpleDraweeView) convertView.findViewById(R.id.item_news_image); holder.Tv_PublishTime = (TextView) convertView.findViewById(R.id.time); holder.Tv_Advertise = (TextView) convertView.findViewById(R.id.advertise); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.Tv_NewsTitle.setText(news.getTitle()); Uri uri = Uri.parse(news.getTitleImg()); holder.Image.setImageURI(uri); if (news.getIsAdv() == Data_DB_News.TYPE_ADVERTISE) { holder.Tv_PublishTime.setVisibility(View.GONE); holder.Tv_Advertise.setVisibility(View.VISIBLE); } else { holder.Tv_PublishTime.setVisibility(View.VISIBLE); String[] timeArray = mDateFormat.format(news.getCreateTime()); StringBuilder publishTime = new StringBuilder(""); for (String s : timeArray) { publishTime.append(s + " "); } holder.Tv_PublishTime.setText(publishTime.toString()); holder.Tv_Advertise.setVisibility(View.GONE); } return convertView; }
@Override public int getItemViewType(int position) { Data_DB_News news = mNewsList.get(position); if (news.getIsAdv() == Data_DB_News.TYPE_NEWS) { return ITEM_TYPE_NEWS; } else if (news.getIsAdv() == Data_DB_News.TYPE_ADVERTISE) { return ITEM_TYPE_ADVERTISE; } return -1; }