android 如何在超链接跳转到activity


public void addIntentLink(final TextView view,final String text) {
   
SpannableString sp = new SpannableString(text);
   
final Intent userIntent = new Intent();

userIntent.setClass(context, UserInfoActivity.class);


sp.setSpan(new IntentSpan(new OnClickListener() { 

public void onClick(View view) { 

           
context.startActivity(userIntent); 

            } 

     }),start,end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        view.setText(sp); 
        view.setMovementMethod(LinkMovementMethod.getInstance()); 
    } 


//IntentSpan 类
public class IntentSpan extends ClickableSpan { 
   
 
        private final OnClickListener listener; 

        public IntentSpan(View.OnClickListener listener) { 
            this.listener = listener; 
        } 

        @Override 
        public void onClick(View view) { 
            listener.onClick(view); 
        } 
    } 

你可能感兴趣的:(SpannableString,addintentlink)