TextView url识别,高亮显示 ,Spannable的使用

 http://yuanzhifei89.iteye.com/blog/983944

 

 在listView 中的textView高亮显示文字                        

@Override
 public View getView(int position, View convertView, ViewGroup parent) {
  ViewHolder viewHolder = null;
  String name = "";
  String phone = "";
  String contactId = null;
  if (null == convertView) {
   viewHolder = new ViewHolder();
   convertView = inflater.inflate(R.layout.dialcontactitem, null);
   viewHolder.imPhoto = (ImageView) convertView
     .findViewById(R.id.ImPhoto);
   viewHolder.tvItemName = (TextView) convertView
     .findViewById(R.id.TvDialContactName);
   viewHolder.tvItemNumAddr = (TextView) convertView
     .findViewById(R.id.TvNumAddr);
   convertView.setTag(viewHolder);
  } else {
   viewHolder = (ViewHolder) convertView.getTag();
  }

  ContactInfo map = contactinfoList.get(position);
  name = map.name;
  phone = map.number;

  contactId = String.valueOf(map.personId);
  viewHolder.tvItemName.setText(name);
     SpannableStringBuilder style=new SpannableStringBuilder(contactinfoList.get(position).number);
     if(end==0){
        style.setSpan(new ForegroundColorSpan(Color.WHITE),0,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
     }
     else {
      style.setSpan(new ForegroundColorSpan(Color.RED),0,end
        ,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  viewHolder.tvItemNumAddr.setText(style);
  return convertView;
 } 
}

 

你可能感兴趣的:(ListView,String,null,url)