zoukankan      html  css  js  c++  java
  • 在TextView文本中实现activity跳转

    		TextView textView = (TextView) this.findViewById(R.id.textview);
    		TextView textView2 = (TextView) this.findViewById(R.id.textview2);
    		String text1 = "显示Activity1";
    		String text2 = "显示Activity2";
    		// 主要是用来拆分字符串
    		SpannableString spannableString = new SpannableString(text1);  
    		SpannableString spannableString2 = new SpannableString(text2);
    		spannableString.setSpan(new ClickableSpan() {
    
    			@Override
    			public void onClick(View widget) {
    				// TODO Auto-generated method stub
    				Intent intent = new Intent(Main.this, Activity1.class);
    				startActivity(intent);
    			}
    		}, 0, text1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //SPAN_EXCLUSIVE_EXCLUSIVE从字符串0-text1.length任意位置触发点击事件
    		spannableString2.setSpan(new ClickableSpan() {
    			@Override
    			public void onClick(View widget) {
    				// TODO Auto-generated method stub
    				Intent intent = new Intent(Main.this, Activity2.class);
    				startActivity(intent);
    			}
    		}, 0, text2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    		textView.setText(spannableString);
    		textView2.setText(spannableString2);
    		textView.setMovementMethod(LinkMovementMethod.getInstance());
    		textView2.setMovementMethod(LinkMovementMethod.getInstance());
    }

    运行结果是:
    
    

      

  • 相关阅读:
    【经典数据结构】B树与B+树
    【经典算法】线性时间排序
    【经典算法】归并排序
    【经典算法】快速排序
    python模块之shelve
    python模块之pickle
    python模块之json
    python之序列化
    python模块之shutil和zipfile
    python模块之sys
  • 原文地址:https://www.cnblogs.com/SoulCode/p/5352835.html
Copyright © 2011-2022 走看看