-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtextgroup2.html
More file actions
1623 lines (1623 loc) · 43.9 KB
/
Copy pathtextgroup2.html
File metadata and controls
1623 lines (1623 loc) · 43.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="App Inventor for Android" name="description" />
<meta content="Android, Blocks App Inventor, Mobile, Phone, IDE" name="keywords" />
<title>
Text Group 2 - App Inventor for Android
</title>
<link href="/static/images/appinventor-16.png" rel="SHORTCUT ICON" type="image/ico" />
<link href="/static/images/appinventor-16.png" rel="icon" type="image/png" />
<link href="/static/css/appinventor.css" rel="stylesheet" />
<script src="http://www.google.com/js/gweb/analytics/autotrack.js">
</script>
<script>
var tracker = new gweb.analytics.AutoTrack({
profile: 'UA-5856106-2'
});
</script>
<script language = "JavaScript" src="/static/scripts/HeaderAndFooter.js"></script>
<style>
img.c3 {border-width:0}
h2.c2 {font-weight: bold}
div.c1 {clear:both;}
</style>
</head>
<body>
<script language = "JavaScript">createHeader('<div id="navigation-breadcrumb"> <a href="/learn/">Learn</a> > Text Group 2 ');</script><br>
<div id="aiac">
<div class="main-container">
<div class="customhr customhr-gray">
</div>
<div class="content">
<div class="content-body">
<div class="learn-page">
<h1>
Text Group Part II: Adding and Removing Members
</h1>
<div class="imagecontainer">
<img align="right" alt="" src="TextGroup2Assets/textGroup2emulator.png" />
</div>
<p>
This tutorial extends the
<a href="/learn/tutorials/textgroup/textgroup.html">
Text
Group tutorial.
</a>
That app sent a text to a fixed list of phone numbers, and only
the programmer could change the numbers in the list. The app in this tutorial
allows the user to add and remove the phone numbers in the list, and it stores the
list persistently in a database.
<br />
</p>
<h2>
Getting Started
</h2>
<p>
Connect to the App Inventor web site and open your textgroup project (if you
haven't completed that tutorial, do so now before continuing). SaveAs the app and
name it "TextGroup2". You can leave the screen's
<span class="ButtonText">
Title
</span>
as "Text Group". Open the Blocks Editor and connect to
the phone.
</p>
<h2>
Introduction
</h2>
<p>
You'll design the app so that the user adds phone numbers to the group by choosing
from the phone's contact list, and removes them by choosing from the items already
in the group.. You'll store the list of numbers in a database so that they are
there even when the app is closed and re-launched.
</p>
<p>
The tutorial covers the following App Inventor components and concepts:
<br />
</p>
<ul>
<li>
The
<span class="ButtonText">
foreach
</span>
block for repeating operations on a
list.
</li>
<li>
The
<span class="ButtonText">
PhoneNumberPicker
</span>
component for accessing
the phone's contacts.
</li>
<li>
The
<span class="ButtonText">
ListPicker
</span>
component for allowing the user
to choose a number for removal.
</li>
<li>
The
<span class="ButtonText">
Texting
</span>
component for sending texts.
</li>
<li>
The
<span class="ButtonText">
TinyDB
</span>
database component for storing the
phone list in a database.
<br />
</li>
</ul>
<h2>
Set up the Components
<br />
</h2>
<p>
The user interface for Text Group, Part II has a textbox, button, and status label
for sending the group text, just as in Part I. If you performed a SaveAs to begin
this project, those components should already be in the view. You should then add a
<span class="ButtonText">
PhoneNumberPicker
</span>
and
<span class="ButtonText">
ListPicker
</span>
components for adding and removing phone numbers
from the list, along with a
<span class="ButtonText">
Texting
</span>
component and a
<span class="ButtonText">
TinyDB
</span>
component, both of which will appear in the
"non-visual" component area. A table of detailed instructions for designing the
components is below, but you can also build it from the following picture of what
it should look like:
</p>
<div class="imagecontainer">
<img alt="" src="TextGroup2Assets/designerPart2.png" width="963" />
</div>
<p>
The components listed below were used to create the designer window shown above.
The first four were part of TextGroup so will already be there if you built that
app and performed a SaveAs to begin this one. You'll need to drag each of the other
components from the
<span class="ButtonText">
Palette
</span>
into the
<span class="ButtonText">
Viewer
</span>
and name it as specified below:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Component Type
</td>
<td class="tbl-header">
Palette Group
</td>
<td class="tbl-header">
What you'll name it
</td>
<td class="tbl-header">
Purpose of Component
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
TextBox
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
MessageText
</span>
</td>
<td>
User will enter message here.
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Button
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
TextGroupButton
</span>
</td>
<td>
user enters the message here
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Label
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
StatusLabel
</span>
</td>
<td>
Reports when texts have been sent
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Texting
</span>
</td>
<td>
Social
</td>
<td>
<span class="ButtonText">
Texting1
</span>
</td>
<td>
The component that sends the texts
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Label
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
GroupHeadingLabel
</span>
</td>
<td>
Header for the list of phone numbers that will appear
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Label
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
MembersLabel
</span>
</td>
<td>
This is where the list of phone numbers will appear
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
Horizontal Arrangement
</span>
</td>
<td>
Screen Arrangement
</td>
<td>
<span class="ButtonText">
Horizontal Arrangement1
</span>
</td>
<td>
To organize the add and remove buttons (pickers) horizontally
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
PhoneNumberPicker
</span>
</td>
<td>
Social
</td>
<td>
<span class="ButtonText">
PhoneNumberPicker1
</span>
</td>
<td>
Allow user to choose from numbers in contact list
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
ListPicker
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
RemoveListPicker
</span>
</td>
<td>
Allow user to remove number from phone numbers in group
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
TinyDB
</span>
</td>
<td>
Basic
</td>
<td>
<span class="ButtonText">
TinyDB1
</span>
</td>
<td>
For storing and retrieving group's phone numbers from database
</td>
</tr>
</tbody>
</table>
</div>
<p>
Set the properties of the components in the following way:
</p>
<ul>
<li>
Set the
<span class="ButtonText">
Hint
</span>
of
<span class="ButtonText">
MessageText
</span>
to "enter a message"
</li>
<li>
Set the
<span class="ButtonText">
Text
</span>
of
<span class="ButtonText">
TextGroupButton
</span>
to "Text Group"
</li>
<li>
Set the
<span class="ButtonText">
Text
</span>
of
<span class="ButtonText">
StatusLabel
</span>
to "status".
</li>
<li>
Set the
<span class="ButtonText">
Text
</span>
of
<span class="ButtonText">
GroupHeadingLabel
</span>
to "-- Group -- ".
</li>
<li>
Set the
<span class="ButtonText">
Text
</span>
of
<span class="ButtonText">
MembersLabel
</span>
to "members will appear here".
</li>
<li>
Set the
<span class="ButtonText">
Text
</span>
of
<span class="ButtonText">
PhoneNumberPicker1
</span>
to "Add Member".
</li>
<li>
Set the
<span class="ButtonText">
Text
</span>
of
<span class="ButtonText">
RemoverListPicker
</span>
to "Remove Member"
</li>
</ul>
<h2>
Add behaviors to the components
<br />
</h2>
<p>
If you completed Text Group, Part I, you should have the following list defined in
the Blocks Editor:
</p>
<div class="imagecontainer">
<img alt="" src="../textgroup/TextGroupAssets/phonelist.png" />
</div>
<p>
For this app, you still want the list but you don't want any pre-defined numbers in
it-- the numbers will be added by the end-user of the app. So remove the text
blocks with the numbers and leave the
<span class="ButtonText">
make a list
</span>
block empty:
</p>
<div class="imagecontainer">
<img alt="" src="TextGroup2Assets/emptylist.png" />
</div>
<p>
You'll need to add the following behaviors:
</p>
<p>
1. When the user clicks the "Add Member" button (the button associated with the
<span class="ButtonText">
PhoneNumberPicker
</span>
), the picker will appear for the
user to choose a number. When the choice is made, the app will add the chosen
number to the
<span class="ButtonText">
PhoneNumbers
</span>
list and update the
database.
</p>
<p>
2. When the user clicks the "Remove Member" button (the button associated with the
<span class="ButtonText">
RemovListPicker
</span>
), the picker will appear for the
user to choose one of the numbers already in
<span class="ButtonText">
PhoneNumbers
</span>
. When the choice is made, the app will remove the
number from the list and update the database.
</p>
<p>
3. When the app begins, the numbers stored in the database are retrieved and loaded
into
<span class="ButtonText">
PhoneNumbers
</span>
.
<br />
</p>
<h2>
<strong>
Adding a
</strong>
Phone Number (Member) to the Group
<br />
</h2>
<p>
The list of phone numbers in the contact list will appear when the user clicks the
<span class="ButtonText">
PhoneNumberPicker
</span>
's associated button: that
behavior is built-in to the component. When the user makes a choice from the
contact list,
<span class="ButtonText">
PhoneNumberPicker
</span>
's
<span class="ButtonText">
AfterPicking
</span>
event is triggered-- your job is to program this
to add the chosen item to the list and update the database.
<br />
</p>
<p>
You'll need the following blocks:
<br />
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Block Type
</td>
<td class="tbl-header">
Drawer
</td>
<td class="tbl-header">
Purpose
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
PhoneNumberPicker1.AfterPicking
</span>
</td>
<td>
PhoneNumberPicker1
</td>
<td>
the event-handler that is triggered when user chooses from contact list
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
add items to list
</span>
</td>
<td>
Lists
<br />
</td>
<td>
your goal is to add chosen number to list
<br />
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
global PhoneNumbers
</span>
</td>
<td>
My Definitions
</td>
<td>
plug this into list slot of add items to list
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
PhoneNumberPicker1.PhoneNumber
</span>
<br />
</td>
<td>
PhoneNumberPicker1
</td>
<td>
this holds the chosen phone number, plug into
<span class="ButtonText">
item
</span>
slot of
<span class="ButtonText">
add items to
list
</span>
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
TinyDB1.StoreValue
</span>
</td>
<td>
TinyDB1
</td>
<td>
since the list is updated, need to update the database
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("textGroup")
</td>
<td>
Text
<br />
</td>
<td>
plug this in as the tag of
<span class="ButtonText">
StoreValue
</span>
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
global PhoneNumbers
</span>
</td>
<td>
My Definitions
</td>
<td>
plug this in as the value of
<span class="ButtonText">
StoreValue
</span>
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
set MembersLabel.Text to
</span>
</td>
<td>
MembersLabel
</td>
<td>
display the list on the phone
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
global PhoneNumbers
</span>
</td>
<td>
My Definitions
</td>
<td>
<span class="ButtonText">
plug into set MembersLabel.Text to
</span>
</td>
</tr>
</tbody>
</table>
</div>
<p>
The blocks should look like this:
</p>
<div class="imagecontainer">
<img alt="" height="270" src="TextGroup2Assets/addMember.png" width="459" />
</div>
<h2>
How the Blocks Work
</h2>
<p>
When the user chooses from the
<span class="ButtonText">
PhoneListPicker,
</span>
the
<span class="ButtonText">
PhoneListPicker1.AfterPicking
</span>
event is triggered.A
<span class="ButtonText">
PhoneListPicker'
</span>
s job is to put the user's choice
in its
<span class="ButtonText">
PhoneNumber
</span>
property, so the event-handler
just calls
<span class="ButtonText">
add items to list
</span>
to get that choice
into the
<span class="ButtonText">
PhoneNumbers
</span>
list.
</p>
<p>
<span class="ButtonText">
PhoneNumbers
</span>
is a variable, and variables are
short-term memory that will disappear when the app is closed. Thus, after adding
the item to the variable,
<span class="ButtonText">
TinyDB1.StoreValue
</span>
block
is used to copy that list to the database-- the phone's long-term memory. The data
is tagged with "textGroup". Later, you'll use that tag to re-load the phone number
list from the database each time the app is opened.
</p>
<p>
After updating the database,
<span class="ButtonText">
set MembersLabel.Text
to
</span>
is called to display the list. This is necessary because list variables
are hidden from the user until they are placed in a visible component. Directly
placing a list into a label is a rudimentary way of displaying a list-- the list
will appear in the form: (111-1111 222-2222). In the next section, you'll program a
more elegant list display..
</p>
<blockquote class="testing">
<strong>
Test the behavior.
</strong>
On the phone, click "Add Member" and choose a
number from the list of contacts that appears. Does the number appear in the
MembersLabel? Try adding additional numbers to see how the list is displayed.
<br />
</blockquote>
<h2 class="c2">
Displaying the List with Items on Separate Lines
</h2>
<p>
At this point the app shows the user the phone numbers that have been added, but
not very elegantly. Create a procedure
<span class="ButtonText">
displayMembers
</span>
, which displays the list with each phone number
on a separate line. Be sure and call the procedure in the
<span class="ButtonText">
PhonePicker1.AfterPicking
</span>
event, below the
<span class="ButtonText">
add items to list
</span>
block, so that the updated list is displayed.
The call to the procedure should replace the blocks that set the MembersLabel.Text
directly to the list. For help displaying the list on separate lines, see
<a href="/learn/reference/other/displaylist.html">
Displaying a List
</a>
</p>
<p>
You'll need the following blocks:
</p>
<div class="advtutorial">
<table>
<tbody>
<tr>
<td class="tbl-header">
Block Type
</td>
<td class="tbl-header">
Drawer
</td>
<td class="tbl-header">
Purpose
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
procedure
</span>
("displayMembers")
</td>
<td>
Definitions
</td>
<td>
create a procedure as you'll want to call this from multiple places
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
set MembersLabel.Text to
</span>
</td>
<td>
MembersLabel
</td>
<td>
display the list here
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("")
</td>
<td>
Text
</td>
<td>
start the text out empty
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
foreach
</span>
</td>
<td>
Control
</td>
<td>
iterate through the numbers
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
name number
</span>
</td>
<td>
in the foreach
</td>
<td>
name the foreach variable "number'. This is the current item of the
<span class="ButtonText">
foreach
</span>
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
global PhoneNumbers
</span>
</td>
<td>
My Definitions
</td>
<td>
plug into
<span class="ButtonText">
in list
</span>
slot of
<span class="ButtonText">
foreach
</span>
</td>
</tr>
<tr>
<td height="30">
<span class="ButtonText">
set MembersLabel.Text to
</span>
</td>
<td>
MembersLabel
</td>
<td>
modify with each of the numbers
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
make text
</span>
</td>
<td>
Text
</td>
<td>
build a text object from multiple parts
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
MembersLabel.Text
</span>
</td>
<td>
MembersLabel
</td>
<td>
add to the label on each iteration of
<span class="ButtonText">
foreach
</span>
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
text
</span>
("\n")
</td>
<td>
Text
</td>
<td>
newline character so that next number is on next line
</td>
</tr>
<tr>
<td>
<span class="ButtonText">
value number
</span>
</td>
<td>
My Definitions
</td>
<td>
the current number from the list
</td>
</tr>
</tbody>
</table>
</div>
<p>
Here's how the blocks should look:
</p>
<div class="imagecontainer">
<img alt="" src="TextGroup2Assets/displayMembers.png" />
</div>
<h2>
How the Blocks Work
</h2>
<p>
The
<span class="ButtonText">
foreach
</span>
in
<span class="ButtonText">
displayMembers
</span>
successively adds a phone number to the end of
the label, placing a newline character in between each item.
</p>
<p>
Of course this procedure will not do anything unless you call it: you should add a
call to the procedure in the
<span class="ButtonText">