android textView 插手毗连体例:3 O) z9 Z; ~- c
1:使用android:autoLink="all" 只需在textview中插手这个属性 在琅缦沔写的文字中包含网址、电话、email的会自动插手毗连地址。
& D* {4 `" N) |* l/ a2 C. j: m 如:7 T- W+ }0 V1 g7 y0 }6 d$ D
- X: h1 R) Q( A, p& h6 `2 i' M3 T
2:uses a string resource containing explicit tags to specify3 ^8 ^/ i, @. `: o; L" |1 r
links.0 h5 k' u$ r( ]7 q8 [: `: ^
如: text2: This is some other7 S% ]+ d5 h# N$ Y4 E, O
text, with a link specified
! F0 p$ K" C" d y via an tag. Use a \"tel:\" URL2 A: ]1 ~" ]. q! a! X4 p
to dial a phone number.
$ f' f" G# z2 q) b * |( r+ h; W: W! e. L% _
别忘了- _+ J9 n: E/ q; R- b. {
TextView t2 = (TextView) findViewById(R.id.text2);
) ]$ O% z! @$ W; D" b ` t2.setMovementMethod(LinkMovementMethod.getInstance());
0 P" ]! E4 s( `; ?$ ]7 r 3: builds the text in the Java code using HTML* Y$ l6 b- z* B5 K
TextView t3 = (TextView) findViewById(R.id.text3);$ C1 G2 [( m% R; N. L6 t5 R3 G1 P* z
t3.setText(Html.fromHtml("text3: Text with a "
8 L8 f7 y2 Z, i( m% C$ \ + "link "7 J- e( l+ S s9 N4 n
+ "created in the Java source code using HTML."));
/ \1 ~# g7 E2 a# p" K8 q t3.setMovementMethod(LinkMovementMethod.getInstance());
8 X3 ~1 I0 A2 r9 J5 N1 I0 N, M 4:字符串进取体例
) R8 t( f8 N- F4 e+ T- u SpannableString ss = new SpannableString("text4: Click here to dial the phone."); c. P9 Z$ R6 k; j
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);* E8 {' Q9 f; e5 h9 ~4 F
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
5 H8 W$ B7 t3 d6 ` F7 S TextView t4 = (TextView) findViewById(R.id.text4);
1 b4 h8 T N4 e9 B- o" Y t4.setText(ss);
& q( f3 i* T1 z0 M, K' Q; p4 p t4.setMovementMethod(LinkMovementMethod.getInstance());
& ?6 a3 ~$ g3 b/ Z1 J+ A- R% I Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,事实下场ScrollView必需只能有一个直接的子类结构。只要在layout中简单设置几个属性就可以轻松实现0 j! ]& `8 e' S+ V) f& A8 E
+ }7 b! ]" d* Y# h V$ v! h 当然我们为了让TextView动起来,还需要用到TextView的setMovementMethod体例设置一个滚动实例,代码如下
( F1 D& S6 H* i1 B* @ TextView tvAndroid123 = (TextView)findViewById(R.id.tvCWJ);
7 m" O' M {/ D- J4 b tvAndroid123.setMovementMethod(ScrollingMovementMethod.getInstance()); // Android开发网提醒相关的可以查看SDK中android.text.method分支体味更多 V2 ~7 w& G2 ^& B% _" d b
ad_link = (TextView) findViewById(R.id.ad_link);% k* x' i9 T; q
ad_link.setText(Html.fromHtml(""+Html.fromHtml(mURL.getLabel()+"")));
' F2 z9 [ t3 g/ K ad_link.setMovementMethod(LinkMovementMethod.getInstance());4 h* h& v1 W* A8 L: E5 k; x
* B, @; }; h4 u) S 5 i$ S2 [2 h7 r# r
ArithmeticExecption:算术异常类:
; S6 g) @9 k8 F, x1 P m
: z/ U1 x' T: r: Z 示例:
7 c$ E8 \9 V- \: @2 B - R, A1 ^8 h z g
package com.darkmi.basic;' h" R6 P9 ?) m9 K2 v
9 p2 X" h* l* o9 o& \* F# Y public class Test {
1 l8 [: e/ p/ w5 M0 I1 P 2 G( S8 k6 y# j
public static void main(String[] args) {
) t/ S$ L" N: o- Q5 i# h 2 o* a/ O# u2 X; J, D5 Q: P) P
int a = 10 / 0;$ ]& i9 X' D- ^$ `1 t# P2 o$ X. j
5 M* ^% C9 v2 }+ C k
System.out.println(a);* u: w4 P, }8 `4 S5 H* N# E& j& k
5 x3 U% [' [/ X3 Z l+ T }
9 }( q+ s5 E) B* y2 Z
+ O ^. V$ n7 v2 `; B: I. b }
. d& }; o' _2 R 1 b4 R( P" A; V7 |" v3 U( m' t- N
异常信息如下:
9 C" h/ j E' e
9 F, ]3 N2 i w7 c Exception in thread "main" java.lang.ArithmeticException: / by zero
4 A) K. Q2 @& V' n" |+ z: j ! ^: k$ h! F& S9 L
at com.darkmi.basic.Test.main(Test.java:6)2 i- s2 E* g+ K$ r, h- d
) r& n" D* t D. e0 }( L ClassCastException:类型强制转换异常/ \$ o- j! v0 E3 h
& ]2 ?/ ]2 J F$ D8 t9 U/ D. v, j 示例:
z. K2 ^! ]% k1 B* t; e" E & C, t: k8 A5 L
package com.darkmi.basic;* t" D7 O. \% D. O% R2 l o# I' z; ]
0 A' s0 }+ | J! S7 s public class Test {
' G. a" m# Y! Z9 i9 u
5 ]. b# z: D+ C0 ~# o; |: r9 ` public static void main(String[] args) {: `# o* ~0 ?: z5 Y( ?1 w' C
5 j. T9 ~% ^4 i testParse("aaa");2 |0 }( e; H6 b
) `$ }. p5 J1 {$ Q. ` z
}
2 R! R$ I% S- N " O6 |* e; C3 E! F2 z
public static void testParse(Object str){
" C5 `3 O9 {' ^+ t8 s) y. K
0 b! _: B1 k! C1 O Integer i = (Integer)str;
( |, o2 j: X+ U0 O' z$ g
0 X$ e( w$ a7 J2 S% ^- } }
+ j+ {: h, D) k6 j3 I
; L! t% R7 T" O$ G% E# X6 e }! E+ t/ e; S; `: e a
6 H3 o( C& o$ [, l n' k
异常信息如下:
8 r" k; w& z M5 Z; ]7 x+ h 5 J5 [7 x# e6 v7 _3 e3 B) j
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
3 E+ v: b( S5 ^5 J; M
) `7 G! C. a; B3 y* w2 z at com.darkmi.basic.Test.testParse(Test.java:10)
; m$ ?2 @5 B) x0 f9 J' @6 g* g
; R ~. @+ p, ]. _) h at com.darkmi.basic.Test.main(Test.java:6) |