一、创建控件
: ~$ ~( U( M/ |/ \& U% Z6 n' s1、创建4个radioButton,和两个text Area控件。% H. c- u+ l. U E+ i
( t; F, V4 ]7 O# @' k$ Z
+ o& c; h1 P/ I$ B6 k7 e
4 ?, @3 L, h0 d6 B- radioButton1 Loacation: X:56 Y: 25. N9 s( d: A* N: v! F
- radioButton2 Loacation: X:56 Y: 78) K3 X; g( `& z0 J4 O
- radioButton3 Loacation: X:56 Y: 129! v q6 t* k9 x7 R; ^
- radioButton4 Loacation: X:56 Y: 179
3 e) I& k/ Q- a" ?" { - selectedText Loacation: X:114 Y: 137
! v+ y: F/ S% U- F; Q - deselectedTextLoacation: X:114 Y: 189
/ K d( Z4 H) b8 Q" K7 [' ?/ O5 C1 g - 同时分别设置四个radioButton的背景图片如下所示:
{! ]# R% \# m' { - radioButton可以在SELECTION栏里设置默认启动时是否选择此radioButton。
复制代码
1 ]# W2 T: t& L; y- p& e
/ M6 g, a- y) b
: m0 p: f3 w: e. X* W然后按照下图给Text Area添加文本资源
5 |0 B& s/ n! c# L8 a
6 [! I+ M4 `4 i+ C* ]) }- K
( A( [: E% o6 ]3 I
( d* _; `3 Z0 Y0 I
二、实现交互4 v8 w/ J5 q2 W( r' O
一共添加8个InterAction,每个radioButton添加一个selected和deselected的InterAction。 ]$ v6 {7 p; h7 K1 X& p- D
& T, c7 ?2 w" Y; T9 J, t
" w6 f0 f3 \( J0 O, p6 `$ q. e
: i+ F8 S0 R2 M- l. n- |
f: {5 {& f6 y依次向8个interactions的code里面添加如下C++代码( y8 F* K8 N# [; j7 ?1 K; G/ Z
! _7 r: w) H8 Q3 ?6 {
- //radioButton1的selected时执行的C++代码
, a; r s0 t0 U$ V- g - Unicode::snprintf(selectedTextBuffer, 4, "%d", 1);
& I9 t* z! A8 [3 M0 O4 @0 [- Z$ S, p - selectedText.resizeToCurrentText();
( k8 P- d+ ~( } - selectedText.invalidate();
复制代码- //radioButton2的selected时执行的C++代码6 a4 T9 h4 k; y4 D8 X
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 2);! l& y j; t+ ?# ?$ X: e+ U: Z
- selectedText.resizeToCurrentText();
1 t8 w5 M" @# r- n0 N; n7 E# H! A - selectedText.invalidate();
复制代码- //radioButton3的selected时执行的C++代码
* I% Q+ S% i( Z& x - Unicode::snprintf(selectedTextBuffer, 4, "%d", 3);
7 w' B, L3 L$ g5 p# L5 C/ d - selectedText.resizeToCurrentText();
4 A$ |7 q' |( A2 P/ }0 i- w - selectedText.invalidate();
复制代码- //radioButton4的selected时执行的C++代码$ @0 `6 U% l, U! n) ^
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 4);
/ _ [! J0 N: T% Z5 X7 w5 N - selectedText.resizeToCurrentText();
0 g$ n. K! b+ k( n - selectedText.invalidate();
复制代码- //radioButton1的deselected时执行的C++代码) U7 D' B- K3 m0 S T
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 1);2 s; g7 J# `& B
- deselectedText.resizeToCurrentText();/ a8 \7 H: E8 ~& m- M
- deselectedText.invalidate();
复制代码- //radioButton2的deselected时执行的C++代码
% d/ T9 u+ T) H0 i# S; Q/ Y - Unicode::snprintf(deselectedTextBuffer, 4, "%d", 2);, |. w1 S; h; ` c' W$ g
- deselectedText.resizeToCurrentText();
/ N0 B& w( P$ h+ [6 P2 c - deselectedText.invalidate();
复制代码- //radioButton3的deselected时执行的C++代码! }$ A: |- l1 \/ H A" b
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 3);1 h! N1 Y5 o% u2 M: j$ j3 [, P+ M( h
- deselectedText.resizeToCurrentText();2 t; u! j$ K* `+ ^
- deselectedText.invalidate();
复制代码- //radioButton4的deselected时执行的C++代码
z7 X& k) r" i/ g1 p - Unicode::snprintf(deselectedTextBuffer, 4, "%d", 4);
: y9 N$ x) k7 H% ^2 f - deselectedText.resizeToCurrentText();3 L& h0 {; K% N. r# T
- deselectedText.invalidate();
复制代码 2 e* {( p# s) I0 m8 F- I- D
Runsimulation即可看到最终演示结果和我们预期相同。1 j& z0 M' J2 S3 e6 J) `
# [5 w% S8 {, \ [5 Y, T
4 x1 O( n) f7 H' ~0 J8 x
3 Y8 M6 O. ?: T* ^! n" B6 X6 k+ }6 B5 q6 F. f, ~
|