示例#1
0
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

      Note note = mNoteList.get(position);
      holder.tvNoteTitle.setText(note.getTitle());

      String time = note.getTime();
      // reformat date to "dd/mm/yyyy"
      Date date = DateUtils.stringToDate(time);
      SimpleDateFormat fomatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
      String newTime = fomatter.format(date);

      String content = note.getContent();
      String newContent = newTime + " " + content;
      // change time's color in textview
      SpannableStringBuilder style = new SpannableStringBuilder(newContent);
      style.setSpan(
          new ForegroundColorSpan(getResources().getColor(R.color.jikelv)),
          0,
          newTime.length(),
          Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
      holder.tvNoteContent.setText(style);

      String imagePath = note.getImagePath();
      if (!TextUtils.isEmpty(imagePath)) {
        mBitmapUtils.display(holder.ivPhoto, imagePath);
        holder.ivPhoto.setVisibility(View.VISIBLE);
      } else {
        holder.ivPhoto.setVisibility(View.GONE);
      }
    }
示例#2
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = View.inflate(MainActivity.this, R.layout.item_list_main, null);
        holder.tvNoteTitle = (TextView) convertView.findViewById(R.id.tvNoteTitle);
        holder.tvNoteContent = (TextView) convertView.findViewById(R.id.tvNoteContent);
        holder.ivPhoto = (ImageView) convertView.findViewById(R.id.ivPhoto);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }

      Note note = mNoteList.get(position);
      holder.tvNoteTitle.setText(note.getTitle());
      String time = note.getTime();

      // reformat date to "dd/mm/yyyy"
      Date date = DateUtils.stringToDate(time);
      SimpleDateFormat fomatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
      String newTime = fomatter.format(date);

      String content = note.getContent();
      String newContent = newTime + " " + content;
      // change time's color in textview
      SpannableStringBuilder style = new SpannableStringBuilder(newContent);
      style.setSpan(
          new ForegroundColorSpan(getResources().getColor(R.color.jikelv)),
          0,
          newTime.length(),
          Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
      holder.tvNoteContent.setText(style);

      String imagePath = note.getImagePath();
      if (!TextUtils.isEmpty(imagePath)) {
        //                Bitmap bitmap = BitmapUtil.getBitmapLocal(MainActivity.this,
        // Uri.parse(imagePath));
        //                Bitmap bitmap = null;
        BitmapUtils bitmapUtils = new BitmapUtils(MainActivity.this);
        bitmapUtils.display(holder.ivPhoto, imagePath);
        //                    bitmap = BitmapFactory.decodeStream(getContentResolver()
        //                            .openInputStream(Uri.parse(imagePath)));
        //                holder.ivPhoto.setImageBitmap(bitmap);
        holder.ivPhoto.setVisibility(View.VISIBLE);
      } else {
        holder.ivPhoto.setVisibility(View.GONE);
      }

      return convertView;
    }