一、创建控件
; f1 b) K" Y' I- m8 b- G' ]1、创建4个radioButton,和两个text Area控件。5 p; n' G |5 |4 Y1 }
d7 N. O* S# W9 u( A% t
% d$ x, a$ k% A/ X9 K/ m
* Q) E* N$ o9 l+ m# n- radioButton1 Loacation: X:56 Y: 25& v" y3 P4 s- V* J) q# B
- radioButton2 Loacation: X:56 Y: 78
4 X6 G4 i+ Q* E6 y8 v" d) Z - radioButton3 Loacation: X:56 Y: 129
& b( ?( C. R7 g& g2 B - radioButton4 Loacation: X:56 Y: 179( v4 U; _. }0 w( ]5 X1 ~ l: Q5 F
- selectedText Loacation: X:114 Y: 137" n0 o L1 y: A/ H( C7 ?5 B/ Z
- deselectedTextLoacation: X:114 Y: 189
0 Y6 e) N( c% c9 E - 同时分别设置四个radioButton的背景图片如下所示:
1 k: r: v/ H. [& ^ - radioButton可以在SELECTION栏里设置默认启动时是否选择此radioButton。
复制代码
5 c: o: q( m. r* x7 i
0 _" m: r I. f* P0 a4 ~; N1 E) @6 [
然后按照下图给Text Area添加文本资源
5 {+ k$ W/ i, r, H3 Q8 L3 u' @+ O [( [ N) D& j
6 c% R- s, R8 j- \
. i, }% P% k8 @; A$ I d' F+ W7 A二、实现交互
! d( V, g9 D8 E9 r8 i一共添加8个InterAction,每个radioButton添加一个selected和deselected的InterAction。
4 g; K% h5 W% b. K. I# X0 _$ p( y4 ]0 w( `6 U5 a4 Q. O8 ~) X8 G
$ \+ m# d. u0 X" S8 Y/ S
# o6 d! K' u' z! \7 q7 A+ \
1 f3 H* Y6 O0 n依次向8个interactions的code里面添加如下C++代码
X& W* o2 Z0 s$ ?
, |4 |( H8 o1 j- //radioButton1的selected时执行的C++代码0 G8 p, W5 j" O. W& L
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 1);' r) L, e$ f2 T, E3 P
- selectedText.resizeToCurrentText();
- E) N6 L4 _* r1 j3 [2 j7 O. c - selectedText.invalidate();
复制代码- //radioButton2的selected时执行的C++代码3 ^7 t+ u% G) i1 R# I. L
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 2);
5 M' V! Q( `% d& { - selectedText.resizeToCurrentText();
4 t8 S% [ k. Q5 z9 u - selectedText.invalidate();
复制代码- //radioButton3的selected时执行的C++代码
5 R9 q6 n: I' f* S/ } - Unicode::snprintf(selectedTextBuffer, 4, "%d", 3);( K# C6 r. R) _3 C; I
- selectedText.resizeToCurrentText();+ K6 A6 T) |- g- O4 R' i' I
- selectedText.invalidate();
复制代码- //radioButton4的selected时执行的C++代码3 W! i$ N, n+ a: U( b" t4 x4 i
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 4);* W- a' K/ R1 j- v- U
- selectedText.resizeToCurrentText();( t7 B$ c2 w3 v" t& O) g
- selectedText.invalidate();
复制代码- //radioButton1的deselected时执行的C++代码! d6 H0 F6 d$ L# ~5 E( K
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 1);: ]0 Y- F+ b1 B; Q! J( w
- deselectedText.resizeToCurrentText();. D: G. A( o5 ~$ H
- deselectedText.invalidate();
复制代码- //radioButton2的deselected时执行的C++代码
. V# p9 K: E! x, m/ y+ `, l% W - Unicode::snprintf(deselectedTextBuffer, 4, "%d", 2);0 x# l9 w& H3 A
- deselectedText.resizeToCurrentText();( m# E# q/ s1 ~% Z
- deselectedText.invalidate();
复制代码- //radioButton3的deselected时执行的C++代码
' f) w$ U8 m8 O, v+ b. y' M - Unicode::snprintf(deselectedTextBuffer, 4, "%d", 3);! Y# ?' k7 u; L& d# g$ T
- deselectedText.resizeToCurrentText();. Z- o6 H9 ~, r. i1 F- `
- deselectedText.invalidate();
复制代码- //radioButton4的deselected时执行的C++代码 z- [* w* `# ^1 W
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 4);
) v) X* w$ j( a7 J/ c - deselectedText.resizeToCurrentText();
1 Z. N8 O3 c3 o, { - deselectedText.invalidate();
复制代码
# ~8 s, N$ E2 E7 K \, y. T+ d; V8 [Runsimulation即可看到最终演示结果和我们预期相同。
# _0 |( k4 f1 S" ?, C( w! D3 b0 k2 L) ^3 E; }' U2 x
* R# ` o3 P @6 N
9 E9 J0 r/ S8 |6 G6 V
2 L+ r+ S8 V3 A4 t) C |