一、创建控件
5 y% W& H- W& C% u. V1、创建4个radioButton,和两个text Area控件。! I9 x; |7 u! {# J9 M& c1 W
: z( J% g$ u& s H4 B, r
$ ?8 W) v* p3 S5 o8 v, i; a! ?
* K9 ]( g! M, E5 E! h- radioButton1 Loacation: X:56 Y: 25% r! C+ _9 j: z/ c) F' o
- radioButton2 Loacation: X:56 Y: 783 K% K2 m# t' l( [, @& n
- radioButton3 Loacation: X:56 Y: 129
. w* M9 I6 i; N5 w: n. Z - radioButton4 Loacation: X:56 Y: 179
7 c8 _( \2 m7 p ^/ v. d- _" W1 t g - selectedText Loacation: X:114 Y: 137' |) f/ d! U& ~$ B/ c; N
- deselectedTextLoacation: X:114 Y: 189
( T' p0 \( v( i6 r% C5 e/ u# Z - 同时分别设置四个radioButton的背景图片如下所示:
8 ?# N+ o4 n, y; I- s/ S# F - radioButton可以在SELECTION栏里设置默认启动时是否选择此radioButton。
复制代码 * X: n+ U. o6 p2 K
( Y& I: i& H( m& i" j
: \( J2 `; a) s+ L( n" ?
然后按照下图给Text Area添加文本资源
S- ]8 X1 x. T$ W, C+ |' Q$ ?8 P; M* G$ {. T/ S. y: w$ m: b
% R5 s, M$ `- Z7 R1 u8 h$ p0 S" u
二、实现交互2 w# [' U$ w* j9 B* s! x
一共添加8个InterAction,每个radioButton添加一个selected和deselected的InterAction。( p& d) ?9 d, }+ y6 R# `, s; k4 \+ V |
2 g) r5 m5 u! i# X" _( V" m' T
4 e1 U! [1 \; J; T1 o
/ F Y6 V! C C4 E2 n; P9 g* A, \! w# c
+ T$ @, ]1 X* y5 h依次向8个interactions的code里面添加如下C++代码" z0 j( w ], o/ n
( h% R. C) w* q, r- //radioButton1的selected时执行的C++代码1 g4 l- ^: j2 _% t. n
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 1); f6 M- M8 @4 q# D7 K( L
- selectedText.resizeToCurrentText();( E; b, ?9 c/ `6 n2 z% E
- selectedText.invalidate();
复制代码- //radioButton2的selected时执行的C++代码
8 {/ E" Q2 a. c5 p5 v - Unicode::snprintf(selectedTextBuffer, 4, "%d", 2);
* v5 G7 Y. X. N z! Q% J9 O9 _( b n - selectedText.resizeToCurrentText();; p. I! Z, S+ f' B- ~) X9 w5 q
- selectedText.invalidate();
复制代码- //radioButton3的selected时执行的C++代码: j3 `7 [9 v; g+ A8 A
- Unicode::snprintf(selectedTextBuffer, 4, "%d", 3);
1 C( t. q, n5 R" ^2 x* I; F - selectedText.resizeToCurrentText();
0 H/ q& M1 r: u1 D* x" e$ U7 n- \ - selectedText.invalidate();
复制代码- //radioButton4的selected时执行的C++代码
7 n6 F7 I) }* c4 l) @& a3 C- Q2 t - Unicode::snprintf(selectedTextBuffer, 4, "%d", 4);' ]; W+ U# j; v
- selectedText.resizeToCurrentText();& E+ a$ [6 @* c3 _* [
- selectedText.invalidate();
复制代码- //radioButton1的deselected时执行的C++代码
, [# R& R4 p$ F( @ - Unicode::snprintf(deselectedTextBuffer, 4, "%d", 1);2 j1 o4 u A; f1 T9 x$ \
- deselectedText.resizeToCurrentText();
. i6 e$ j. o, t* D: x% N - deselectedText.invalidate();
复制代码- //radioButton2的deselected时执行的C++代码1 a1 C) A- a2 o6 B: ]
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 2);
- t' V$ _5 L2 N" ^+ ?6 ~3 ] - deselectedText.resizeToCurrentText();
' t" d) l$ O3 ~# C5 G - deselectedText.invalidate();
复制代码- //radioButton3的deselected时执行的C++代码1 h( I% {- |- b! {* Z' e
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 3);3 V% x% k$ y! C' v, _2 f; s
- deselectedText.resizeToCurrentText();7 n2 D. h/ L1 W$ s* m8 v; p
- deselectedText.invalidate();
复制代码- //radioButton4的deselected时执行的C++代码% B0 u5 n, Y p- h% X& @! t) X
- Unicode::snprintf(deselectedTextBuffer, 4, "%d", 4);+ u% G* P: w* q0 B
- deselectedText.resizeToCurrentText();
' c! E1 \- c$ ` - deselectedText.invalidate();
复制代码 0 v4 l! @# a' _' a
Runsimulation即可看到最终演示结果和我们预期相同。6 N/ ` X: o# T
& c7 f3 g1 a% a+ l; b
- B2 _' u* L5 ?7 |9 K% f: U& Y
+ r( p! `0 T9 i" h1 l4 K" q; r& g" g" [- o5 J
|