Пример #1
0
  /** ListView Item设置 */
  public View getView(int position, View convertView, ViewGroup parent) {
    // Log.d("method", "getView");

    // 自定义视图
    ListItemView listItemView = null;

    if (convertView == null) {
      // 获取list_item布局文件的视图
      convertView = listContainer.inflate(this.itemViewResource, null);

      listItemView = new ListItemView();
      // 获取控件对象
      listItemView.title = (TextView) convertView.findViewById(R.id.cate_listitem_title);
      listItemView.author = (TextView) convertView.findViewById(R.id.cate_listitem_author);
      listItemView.count = (TextView) convertView.findViewById(R.id.cate_listitem_commentCount);
      listItemView.date = (TextView) convertView.findViewById(R.id.cate_listitem_date);
      listItemView.type = (ImageView) convertView.findViewById(R.id.cate_listitem_documentType);

      // 设置控件集到convertView
      convertView.setTag(listItemView);
    } else {
      listItemView = (ListItemView) convertView.getTag();
    }

    // 设置文字和图片
    Category cate = listItems.get(position);

    listItemView.title.setText(cate.getTitle());
    listItemView.title.setTag(cate); // 设置隐藏参数(实体类)
    listItemView.date.setText(StringUtils.friendly_time(cate.getPubDate()));
    listItemView.count.setText(cate.getCommentCount() + "");
    if (cate.getDocumentType() == cate.DOC_TYPE_ORIGINAL)
      listItemView.type.setImageResource(R.drawable.widget_original_icon);
    else listItemView.type.setImageResource(R.drawable.widget_repaste_icon);

    if (cateType == CategoryList.CATALOG_USER) {
      listItemView.author.setVisibility(View.GONE);
    } else {
      listItemView.author.setText(cate.getAuthor() + "   发表于");
    }

    return convertView;
  }