Ejemplo n.º 1
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Log.d(TAG, "Item点击:" + position);
    // 获取头布局数量
    int headerViewsCount = lvList.getHeaderViewsCount();
    // 需要减去头布局的占位
    position = position - headerViewsCount;
    System.out.println("第" + position + "个被点击了");
    if (mNewsList != null) {
      News news = mNewsList.get(position);
      Log.d(TAG, "新闻id=" + news.id + "; 新闻标题=" + news.title);
      // 35314,35315,35316
      String ids = SharePreferenceUtils.getString(mActivity, PREF_NEWS_READ, "");
      // 只有在不包含该id时才添加
      if (!ids.contains(news.id)) {
        ids = ids + news.id + ",";
        // 更新已读id列表
        SharePreferenceUtils.putString(mActivity, PREF_NEWS_READ, ids);
      }
      // 刷新ListView
      // mNewsAdapter.notifyDataSetChanged();
      // 局部刷新ListView
      mNewsAdapter.changeTextColor(view);

      Intent intent = new Intent(mActivity, NewsDetailActivity.class);
      intent.putExtra("news_url", news.url);
      mActivity.startActivity(intent);
    }
  }
Ejemplo n.º 2
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        convertView = View.inflate(mActivity, R.layout.list_item_news, null);
        holder = new ViewHolder();
        holder.ivIcon = (ImageView) convertView.findViewById(R.id.iv_icon);
        holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
        holder.tvDate = (TextView) convertView.findViewById(R.id.tv_date);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      News news = getItem(position);
      holder.tvTitle.setText(news.title);
      holder.tvDate.setText(news.pubdate);

      mBitmapUtils.display(holder.ivIcon, news.listimage);
      String ids = SharePreferenceUtils.getString(mActivity, PREF_NEWS_READ, "");
      // 如果再已读列表中
      if (ids.contains(getItem(position).id)) {
        holder.tvTitle.setTextColor(Color.GRAY);
      } else {
        holder.tvTitle.setTextColor(Color.BLACK);
      }
      return convertView;
    }