コード例 #1
0
  @Override
  public void onBindViewHolder(final ViewHolder holder, final int position) {
    String order;
    if (holder.sortingType.equals("0")) {
      switch (position) {
        case 0:
          order = holder.mContext.getString(R.string.firtime);
          break;
        case 1:
          order = holder.mContext.getString(R.string.sectime);
          break;
        default:
          order = String.valueOf(position + 1) + ".";
          break;
      }
    } else {
      if (position == mThoughtList.length() - 1) {
        order = holder.mContext.getString(R.string.firtime);
      } else if (position == mThoughtList.length() - 2) {
        order = holder.mContext.getString(R.string.sectime);
      } else {
        order = String.valueOf(mThoughtList.length() - position) + ".";
      }
    }
    holder.tvOrder.setText(order);

    long time = mThoughtList.get(position).getTimeStamp();
    holder.tvThought.setText(mThoughtList.get(position).getThought());
    holder.tvTime.setText(TimeUtils.parseTime(holder.mContext, time));

    if (mThoughtList.get(position).hasImage()) {
      holder.mImage.setVisibility(View.VISIBLE);
      Glide.with(holder.mContext)
          .load(GalleryUtils.getImagePath(mThoughtList.get(position).getPath()))
          .into(holder.mImage);
      holder.mImage.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Intent i = new Intent(holder.mContext, GalleryActivity.class);
              i.putExtra(GalleryActivity.PATH, mThoughtList.get(position).getPath());
              holder.mContext.startActivity(i);
            }
          });
    } else {
      holder.mImage.setVisibility(View.GONE);
    }

    holder.mView.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            Intent i = new Intent(holder.mContext, AddEditThoughtActivity.class);
            i.putExtra(AddEditThoughtActivity.MODE, AddEditThoughtActivity.MODE_EDIT);
            i.putExtra(AddEditThoughtActivity.THOUGHT_ID, mThoughtList.get(position).getKey());
            i.putExtra(AddEditThoughtActivity.THOUGHT, mThoughtList.get(position).getThought());
            i.putExtra(Thoughts.Thought.THOUGHT_RES, mThoughtList.get(position).getResType());
            i.putExtra(Thoughts.Thought.THOUGHT_PATH, mThoughtList.get(position).getPath());
            i.putExtra(AddEditThoughtActivity.TIMESTAMP, mThoughtList.get(position).getTimeStamp());
            holder.mContext.startActivity(i);
            return true;
          }
        });
  }
コード例 #2
0
 @Override
 public int getItemCount() {
   return mThoughtList.length();
 }