当前位置: 首页>>代码示例>>Java>>正文


Java SpannableStringBuilder.clearSpans方法代码示例

本文整理汇总了Java中android.text.SpannableStringBuilder.clearSpans方法的典型用法代码示例。如果您正苦于以下问题:Java SpannableStringBuilder.clearSpans方法的具体用法?Java SpannableStringBuilder.clearSpans怎么用?Java SpannableStringBuilder.clearSpans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.SpannableStringBuilder的用法示例。


在下文中一共展示了SpannableStringBuilder.clearSpans方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getText

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
/**
 * @param context
 * @param spannable
 * @param title
 * @return
 */
public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) {
	if (spannable == null || spannable.length() <= 0) {
		Log.e(TAG, "getText  spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();");
		return new SpannableStringBuilder();
	}

	SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
	builder.clearSpans();// should clear old spans
	URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class);
	if (urls != null) {
		for (URLSpan urlSpan : urls) {
			if (urlSpan != null) {
				MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title);
				builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable
						.getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			}
		}
	}

	return builder;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:MyURLSpan.java

示例2: bind

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
@Override
void bind(Context context) {
    try {
        CharSequence charSequence = Html.fromHtml(message.getMsgContent());
        String msg = charSequence.toString();
        if (msg.endsWith("\n\n")) {
             charSequence = charSequence.subSequence(0, charSequence.length() - 2);
        }
        rich_tvmsg.setText(charSequence);
        rich_tvmsg.setMovementMethod(LinkMovementMethod.getInstance());
        CharSequence text = rich_tvmsg.getText();
        if (text instanceof Spannable) {
            int end = text.length();
            Spannable sp = (Spannable) rich_tvmsg.getText();
            URLSpan[] urls = sp.getSpans(0, end, URLSpan.class);
            SpannableStringBuilder style = new SpannableStringBuilder(text);
            style.clearSpans();// should clear old spans
            for (URLSpan url : urls) {
                MyURLSpan myURLSpan = new MyURLSpan(url.getURL());
                style.setSpan(myURLSpan, sp.getSpanStart(url),
                        sp.getSpanEnd(url),
                        Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
            }
            rich_tvmsg.setText(style);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } catch (OutOfMemoryError error) {
        error.printStackTrace();
    }

}
 
开发者ID:lennyup,项目名称:react-native-udesk,代码行数:33,代码来源:MessageAdatper.java

示例3: getView

import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //其实评论一般都是文字,高级点的带有图片评论,光文字的话复用不复用就没什么大区别了
    View view = null;
    if(convertView!=null)
    {
        view = convertView;
    }
    else
    {
        view = LayoutInflater.from(context).inflate(R.layout.listview_item, parent,false);
    }
    ViewHolder holder = (ViewHolder) view.getTag();
    if(holder==null)
    {
        holder = new ViewHolder();
        holder.txt_comment = (TextView) view.findViewById(R.id.txt_comment);

        view.setTag(holder);
    }
    //给相应位置的文字赋内容
    if (name != null && name.size()!=0) {
        StringBuilder actionText = new StringBuilder();

        //谁回复
        actionText.append("<a style=\"text-decoration:none;\" href='name' ><font color='#1468a3'>"
                + name.get(position)  + "</font> </a>");

        // 回复谁,被回复的人可能不存在。
        if(toName.get(position)!=null&&toName.get(position).length()>0) {
            actionText.append("回复");
            actionText.append("<font color='#1468a3'><a style=\"text-decoration:none;\" href='toName'>"
                    + toName.get(position) + " " + " </a></font>");
        }
        // 内容
        actionText.append("<font color='#484848'><a style=\"text-decoration:none;\" href='content'>"
                + ":" + content.get(position) + " " + " </a></font>");

        holder.txt_comment.setText(Html.fromHtml(actionText.toString()));
        holder.txt_comment.setMovementMethod(LinkMovementMethod
                .getInstance());
        CharSequence text = holder.txt_comment.getText();
        int ends = text.length();
        Spannable spannable = (Spannable) holder.txt_comment.getText();
        URLSpan[] urlspan = spannable.getSpans(0, ends, URLSpan.class);
        SpannableStringBuilder stylesBuilder = new SpannableStringBuilder(text);
        stylesBuilder.clearSpans();

        for (URLSpan url : urlspan) {
            FeedTextViewURLSpan myURLSpan = new FeedTextViewURLSpan(url.getURL(),
                    context,name.get(position),toName.get(position),content.get(position));
            stylesBuilder.setSpan(myURLSpan, spannable.getSpanStart(url),
                    spannable.getSpanEnd(url), spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        holder.txt_comment.setText(stylesBuilder);
        holder.txt_comment.setFocusable(false);
        holder.txt_comment.setClickable(false);
        holder.txt_comment.setLongClickable(false);

    }

    return view;
}
 
开发者ID:xzh1223,项目名称:ReplyDemo,代码行数:64,代码来源:CommentAdapter.java


注:本文中的android.text.SpannableStringBuilder.clearSpans方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。