-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata-views.html
More file actions
725 lines (674 loc) · 74.2 KB
/
data-views.html
File metadata and controls
725 lines (674 loc) · 74.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Android Development: Lecture Notes</title>
<meta name="description" content="Lecture Notes for INFO 448: Android Development.">
<meta name="generator" content="bookdown 0.5 and GitBook 2.6.7">
<meta property="og:title" content="Android Development: Lecture Notes" />
<meta property="og:type" content="book" />
<meta property="og:url" content="https://info448.github.io/" />
<meta property="og:image" content="https://info448.github.io/img/android_icon_transparent.png" />
<meta property="og:description" content="Lecture Notes for INFO 448: Android Development." />
<meta name="github-repo" content="info448/book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Android Development: Lecture Notes" />
<meta name="twitter:description" content="Lecture Notes for INFO 448: Android Development." />
<meta name="twitter:image" content="https://info448.github.io/img/android_icon_transparent.png" />
<meta name="author" content="Joel Ross">
<meta name="date" content="2018-11-19">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="shortcut icon" href="img/android_icon_transparent.png" type="image/x-icon">
<link rel="prev" href="activities.html">
<link rel="next" href="material-design.html">
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-98444716-1', 'auto');
ga('send', 'pageview');
</script>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./" class="title">Android Development</a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>About this Book</a></li>
<li class="part"><span><b>I Lectures</b></span></li>
<li class="chapter" data-level="1" data-path="introduction.html"><a href="introduction.html"><i class="fa fa-check"></i><b>1</b> Introduction</a><ul>
<li class="chapter" data-level="1.1" data-path="introduction.html"><a href="introduction.html#android-history"><i class="fa fa-check"></i><b>1.1</b> Android History</a><ul>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#android-versions"><i class="fa fa-check"></i>Android Versions</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#legal-battles"><i class="fa fa-check"></i>Legal Battles</a></li>
</ul></li>
<li class="chapter" data-level="1.2" data-path="introduction.html"><a href="introduction.html#building-apps"><i class="fa fa-check"></i><b>1.2</b> Building Apps</a><ul>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#creating-a-project"><i class="fa fa-check"></i>Creating a Project</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#running-the-app"><i class="fa fa-check"></i>Running the App</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path="introduction.html"><a href="introduction.html#app-source-code"><i class="fa fa-check"></i><b>1.3</b> App Source Code</a><ul>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#xml-resources"><i class="fa fa-check"></i>XML Resources</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#the-manifest"><i class="fa fa-check"></i>The Manifest</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#java-activities"><i class="fa fa-check"></i>Java Activities</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#gradle-scripts"><i class="fa fa-check"></i>Gradle Scripts</a></li>
</ul></li>
<li class="chapter" data-level="1.4" data-path="introduction.html"><a href="introduction.html#logging-adb"><i class="fa fa-check"></i><b>1.4</b> Logging & ADB</a><ul>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#log-methods"><i class="fa fa-check"></i>Log Methods</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#logcat"><i class="fa fa-check"></i>Logcat</a></li>
<li class="chapter" data-level="" data-path="introduction.html"><a href="introduction.html#toast"><i class="fa fa-check"></i>Toast</a></li>
</ul></li>
<li class="chapter" data-level="1.5" data-path="introduction.html"><a href="introduction.html#adding-interaction"><i class="fa fa-check"></i><b>1.5</b> Adding Interaction</a></li>
<li class="chapter" data-level="1.6" data-path="introduction.html"><a href="introduction.html#kotlin-setup"><i class="fa fa-check"></i><b>1.6</b> Kotlin</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html"><i class="fa fa-check"></i><b>2</b> Resources and Layouts</a><ul>
<li class="chapter" data-level="2.1" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#resources"><i class="fa fa-check"></i><b>2.1</b> Resources</a><ul>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#r"><i class="fa fa-check"></i>R</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#alternative-resources"><i class="fa fa-check"></i>Alternative Resources</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#views"><i class="fa fa-check"></i><b>2.2</b> Views</a><ul>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#view-properties"><i class="fa fa-check"></i>View Properties</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#views-and-java"><i class="fa fa-check"></i>Views and Java</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#practice"><i class="fa fa-check"></i>Practice</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#layouts"><i class="fa fa-check"></i><b>2.3</b> Layouts</a><ul>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#linearlayout"><i class="fa fa-check"></i>LinearLayout</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#relativelayout"><i class="fa fa-check"></i>RelativeLayout</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#constraintlayout"><i class="fa fa-check"></i>ConstraintLayout</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#other-layouts"><i class="fa fa-check"></i>Other Layouts</a></li>
<li class="chapter" data-level="" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#combining-and-inflating-layouts"><i class="fa fa-check"></i>Combining and Inflating Layouts</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="resources-and-layouts.html"><a href="resources-and-layouts.html#inputs"><i class="fa fa-check"></i><b>2.4</b> Inputs</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="activities.html"><a href="activities.html"><i class="fa fa-check"></i><b>3</b> Activities</a><ul>
<li class="chapter" data-level="3.1" data-path="activities.html"><a href="activities.html#making-activities"><i class="fa fa-check"></i><b>3.1</b> Making Activities</a></li>
<li class="chapter" data-level="3.2" data-path="activities.html"><a href="activities.html#the-activity-lifecycle"><i class="fa fa-check"></i><b>3.2</b> The Activity Lifecycle</a><ul>
<li class="chapter" data-level="" data-path="activities.html"><a href="activities.html#overriding-the-callback-methods"><i class="fa fa-check"></i>Overriding the Callback Methods</a></li>
<li class="chapter" data-level="" data-path="activities.html"><a href="activities.html#saving-and-restoring-activity-state"><i class="fa fa-check"></i>Saving and Restoring Activity State</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="activities.html"><a href="activities.html#context"><i class="fa fa-check"></i><b>3.3</b> Context</a></li>
<li class="chapter" data-level="3.4" data-path="activities.html"><a href="activities.html#multiple-activities"><i class="fa fa-check"></i><b>3.4</b> Multiple Activities</a><ul>
<li class="chapter" data-level="" data-path="activities.html"><a href="activities.html#activity-intents"><i class="fa fa-check"></i>Intents</a></li>
<li class="chapter" data-level="" data-path="activities.html"><a href="activities.html#back-tasks"><i class="fa fa-check"></i>Back & Tasks</a></li>
<li class="chapter" data-level="" data-path="activities.html"><a href="activities.html#up-navigation"><i class="fa fa-check"></i>Up Navigation</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="data-views.html"><a href="data-views.html"><i class="fa fa-check"></i><b>4</b> Data-Driven Views</a><ul>
<li class="chapter" data-level="4.1" data-path="data-views.html"><a href="data-views.html#listviews-and-adapters"><i class="fa fa-check"></i><b>4.1</b> ListViews and Adapters</a></li>
<li class="chapter" data-level="4.2" data-path="data-views.html"><a href="data-views.html#networking-with-volley"><i class="fa fa-check"></i><b>4.2</b> Networking with Volley</a><ul>
<li class="chapter" data-level="" data-path="data-views.html"><a href="data-views.html#using-volley"><i class="fa fa-check"></i>Using Volley</a></li>
<li class="chapter" data-level="" data-path="data-views.html"><a href="data-views.html#requestqueue-singletons"><i class="fa fa-check"></i>RequestQueue Singletons</a></li>
<li class="chapter" data-level="" data-path="data-views.html"><a href="data-views.html#downloading-images"><i class="fa fa-check"></i>Downloading Images</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="5" data-path="material-design.html"><a href="material-design.html"><i class="fa fa-check"></i><b>5</b> Material Design</a><ul>
<li class="chapter" data-level="5.1" data-path="material-design.html"><a href="material-design.html#the-material-design-language"><i class="fa fa-check"></i><b>5.1</b> The Material Design Language</a></li>
<li class="chapter" data-level="5.2" data-path="material-design.html"><a href="material-design.html#material-styles-icons"><i class="fa fa-check"></i><b>5.2</b> Material Styles & Icons</a></li>
<li class="chapter" data-level="5.3" data-path="material-design.html"><a href="material-design.html#design-support-libraries"><i class="fa fa-check"></i><b>5.3</b> Design Support Libraries</a><ul>
<li class="chapter" data-level="" data-path="material-design.html"><a href="material-design.html#widgets"><i class="fa fa-check"></i>Widgets</a></li>
<li class="chapter" data-level="" data-path="material-design.html"><a href="material-design.html#coordinator-layout"><i class="fa fa-check"></i>Coordinator Layout</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="material-design.html"><a href="material-design.html#animations"><i class="fa fa-check"></i><b>5.4</b> Animations</a></li>
<li class="chapter" data-level="" data-path="material-design.html"><a href="material-design.html#resources-1"><i class="fa fa-check"></i>Resources</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="fragments.html"><a href="fragments.html"><i class="fa fa-check"></i><b>6</b> Fragments</a><ul>
<li class="chapter" data-level="6.1" data-path="fragments.html"><a href="fragments.html#creating-a-fragment"><i class="fa fa-check"></i><b>6.1</b> Creating a Fragment</a><ul>
<li class="chapter" data-level="" data-path="fragments.html"><a href="fragments.html#activity-to-fragment-communication"><i class="fa fa-check"></i>Activity-to-Fragment Communication</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="fragments.html"><a href="fragments.html#dynamic-fragments"><i class="fa fa-check"></i><b>6.2</b> Dynamic Fragments</a><ul>
<li class="chapter" data-level="" data-path="fragments.html"><a href="fragments.html#instantiating-fragments"><i class="fa fa-check"></i>Instantiating Fragments</a></li>
<li class="chapter" data-level="" data-path="fragments.html"><a href="fragments.html#transactions"><i class="fa fa-check"></i>Transactions</a></li>
<li class="chapter" data-level="" data-path="fragments.html"><a href="fragments.html#inter-fragment-communication"><i class="fa fa-check"></i>Inter-Fragment Communication</a></li>
<li class="chapter" data-level="" data-path="fragments.html"><a href="fragments.html#the-back-stack"><i class="fa fa-check"></i>The Back Stack</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="intents.html"><a href="intents.html"><i class="fa fa-check"></i><b>7</b> Intents</a><ul>
<li class="chapter" data-level="7.1" data-path="intents.html"><a href="intents.html#intents-for-another-activity-explicit"><i class="fa fa-check"></i><b>7.1</b> Intents for Another Activity (Explicit)</a><ul>
<li class="chapter" data-level="" data-path="intents.html"><a href="intents.html#extras"><i class="fa fa-check"></i>Extras</a></li>
</ul></li>
<li class="chapter" data-level="7.2" data-path="intents.html"><a href="intents.html#intents-for-another-app-implicit"><i class="fa fa-check"></i><b>7.2</b> Intents for Another App (Implicit)</a></li>
<li class="chapter" data-level="7.3" data-path="intents.html"><a href="intents.html#intents-for-a-response"><i class="fa fa-check"></i><b>7.3</b> Intents for a Response</a></li>
<li class="chapter" data-level="7.4" data-path="intents.html"><a href="intents.html#listening-for-intents"><i class="fa fa-check"></i><b>7.4</b> Listening for Intents</a></li>
<li class="chapter" data-level="7.5" data-path="intents.html"><a href="intents.html#broadcasts-and-receivers"><i class="fa fa-check"></i><b>7.5</b> Broadcasts and Receivers</a></li>
<li class="chapter" data-level="7.6" data-path="intents.html"><a href="intents.html#menus"><i class="fa fa-check"></i><b>7.6</b> Menus</a><ul>
<li class="chapter" data-level="" data-path="intents.html"><a href="intents.html#action-views"><i class="fa fa-check"></i>Action Views</a></li>
<li class="chapter" data-level="" data-path="intents.html"><a href="intents.html#context-menus"><i class="fa fa-check"></i>Context Menus</a></li>
</ul></li>
<li class="chapter" data-level="7.7" data-path="intents.html"><a href="intents.html#an-intent-example-sms"><i class="fa fa-check"></i><b>7.7</b> An Intent Example: SMS</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="notifications-settings.html"><a href="notifications-settings.html"><i class="fa fa-check"></i><b>8</b> Notifications & Settings</a><ul>
<li class="chapter" data-level="8.1" data-path="notifications-settings.html"><a href="notifications-settings.html#dialogs"><i class="fa fa-check"></i><b>8.1</b> Dialogs</a><ul>
<li class="chapter" data-level="" data-path="notifications-settings.html"><a href="notifications-settings.html#dialogfragments"><i class="fa fa-check"></i>DialogFragments</a></li>
</ul></li>
<li class="chapter" data-level="8.2" data-path="notifications-settings.html"><a href="notifications-settings.html#notifications"><i class="fa fa-check"></i><b>8.2</b> Notifications</a><ul>
<li class="chapter" data-level="8.2.1" data-path="notifications-settings.html"><a href="notifications-settings.html#tap-actions"><i class="fa fa-check"></i><b>8.2.1</b> Tap Actions</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="notifications-settings.html"><a href="notifications-settings.html#settings"><i class="fa fa-check"></i><b>8.3</b> Settings</a><ul>
<li class="chapter" data-level="" data-path="notifications-settings.html"><a href="notifications-settings.html#sharedpreferences"><i class="fa fa-check"></i>SharedPreferences</a></li>
<li class="chapter" data-level="" data-path="notifications-settings.html"><a href="notifications-settings.html#preference-settings"><i class="fa fa-check"></i>Preference Settings</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="9" data-path="loaders.html"><a href="loaders.html"><i class="fa fa-check"></i><b>9</b> Providers and Loaders</a><ul>
<li class="chapter" data-level="9.1" data-path="loaders.html"><a href="loaders.html#content-providers-intro"><i class="fa fa-check"></i><b>9.1</b> Content Providers</a></li>
<li class="chapter" data-level="9.2" data-path="loaders.html"><a href="loaders.html#cursors"><i class="fa fa-check"></i><b>9.2</b> Cursors</a></li>
<li class="chapter" data-level="9.3" data-path="loaders.html"><a href="loaders.html#loaders"><i class="fa fa-check"></i><b>9.3</b> Loaders</a></li>
<li class="chapter" data-level="9.4" data-path="loaders.html"><a href="loaders.html#other-provider-actions"><i class="fa fa-check"></i><b>9.4</b> Other Provider Actions</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="files-and-permissions.html"><a href="files-and-permissions.html"><i class="fa fa-check"></i><b>10</b> Files and Permissions</a><ul>
<li class="chapter" data-level="10.1" data-path="files-and-permissions.html"><a href="files-and-permissions.html#file-storage-locations"><i class="fa fa-check"></i><b>10.1</b> File Storage Locations</a></li>
<li class="chapter" data-level="10.2" data-path="files-and-permissions.html"><a href="files-and-permissions.html#permissions"><i class="fa fa-check"></i><b>10.2</b> Permissions</a></li>
<li class="chapter" data-level="10.3" data-path="files-and-permissions.html"><a href="files-and-permissions.html#external-storage"><i class="fa fa-check"></i><b>10.3</b> External Storage</a></li>
<li class="chapter" data-level="10.4" data-path="files-and-permissions.html"><a href="files-and-permissions.html#internal-storage-cache"><i class="fa fa-check"></i><b>10.4</b> Internal Storage & Cache</a></li>
<li class="chapter" data-level="10.5" data-path="files-and-permissions.html"><a href="files-and-permissions.html#example-saving-pictures"><i class="fa fa-check"></i><b>10.5</b> Example: Saving Pictures</a><ul>
<li class="chapter" data-level="10.5.1" data-path="files-and-permissions.html"><a href="files-and-permissions.html#fileproviders"><i class="fa fa-check"></i><b>10.5.1</b> FileProviders</a></li>
</ul></li>
<li class="chapter" data-level="10.6" data-path="files-and-permissions.html"><a href="files-and-permissions.html#sharing-files"><i class="fa fa-check"></i><b>10.6</b> Sharing Files</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="databases.html"><a href="databases.html"><i class="fa fa-check"></i><b>11</b> Providers and Databases</a><ul>
<li class="chapter" data-level="11.1" data-path="databases.html"><a href="databases.html#review-providers-and-loaders"><i class="fa fa-check"></i><b>11.1</b> Review: Providers and Loaders</a></li>
<li class="chapter" data-level="11.2" data-path="databases.html"><a href="databases.html#sqlite-databases"><i class="fa fa-check"></i><b>11.2</b> SQLite Databases</a></li>
<li class="chapter" data-level="11.3" data-path="databases.html"><a href="databases.html#implementing-a-contentprovider"><i class="fa fa-check"></i><b>11.3</b> Implementing a ContentProvider</a><ul>
<li class="chapter" data-level="" data-path="databases.html"><a href="databases.html#uris-and-types"><i class="fa fa-check"></i>URIs and Types</a></li>
<li class="chapter" data-level="" data-path="databases.html"><a href="databases.html#query-methods"><i class="fa fa-check"></i>Query Methods</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="12" data-path="location.html"><a href="location.html"><i class="fa fa-check"></i><b>12</b> Location</a><ul>
<li class="chapter" data-level="12.1" data-path="location.html"><a href="location.html#localization-techniques"><i class="fa fa-check"></i><b>12.1</b> Localization Techniques</a><ul>
<li class="chapter" data-level="" data-path="location.html"><a href="location.html#gps"><i class="fa fa-check"></i>GPS</a></li>
<li class="chapter" data-level="" data-path="location.html"><a href="location.html#cell-tower-localization"><i class="fa fa-check"></i>Cell Tower Localization</a></li>
<li class="chapter" data-level="" data-path="location.html"><a href="location.html#wifi-localization"><i class="fa fa-check"></i>WiFi Localization</a></li>
<li class="chapter" data-level="" data-path="location.html"><a href="location.html#representing-location"><i class="fa fa-check"></i>Representing Location</a></li>
</ul></li>
<li class="chapter" data-level="12.2" data-path="location.html"><a href="location.html#android-location"><i class="fa fa-check"></i><b>12.2</b> Android Location</a><ul>
<li class="chapter" data-level="" data-path="location.html"><a href="location.html#google-play-services"><i class="fa fa-check"></i>Google Play Services</a></li>
<li class="chapter" data-level="" data-path="location.html"><a href="location.html#accessing-location"><i class="fa fa-check"></i>Accessing Location</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="13" data-path="services.html"><a href="services.html"><i class="fa fa-check"></i><b>13</b> Threads and Services</a><ul>
<li class="chapter" data-level="13.1" data-path="services.html"><a href="services.html#threads-and-processes"><i class="fa fa-check"></i><b>13.1</b> Threads and Processes</a><ul>
<li class="chapter" data-level="" data-path="services.html"><a href="services.html#java-threads"><i class="fa fa-check"></i>Java Threads</a></li>
<li class="chapter" data-level="" data-path="services.html"><a href="services.html#android-threads"><i class="fa fa-check"></i>Android Threads</a></li>
</ul></li>
<li class="chapter" data-level="13.2" data-path="services.html"><a href="services.html#intentservices"><i class="fa fa-check"></i><b>13.2</b> IntentServices</a><ul>
<li class="chapter" data-level="" data-path="services.html"><a href="services.html#the-service-lifecycle"><i class="fa fa-check"></i>The Service Lifecycle</a></li>
</ul></li>
<li class="chapter" data-level="13.3" data-path="services.html"><a href="services.html#example-a-music-service"><i class="fa fa-check"></i><b>13.3</b> Example: A Music Service</a><ul>
<li class="chapter" data-level="" data-path="services.html"><a href="services.html#mediaplayer"><i class="fa fa-check"></i>MediaPlayer</a></li>
<li class="chapter" data-level="" data-path="services.html"><a href="services.html#creating-a-service"><i class="fa fa-check"></i>Creating a Service</a></li>
</ul></li>
<li class="chapter" data-level="13.4" data-path="services.html"><a href="services.html#foreground-services"><i class="fa fa-check"></i><b>13.4</b> Foreground Services</a></li>
<li class="chapter" data-level="13.5" data-path="services.html"><a href="services.html#bound-services"><i class="fa fa-check"></i><b>13.5</b> Bound Services</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="sensors.html"><a href="sensors.html"><i class="fa fa-check"></i><b>14</b> Sensors</a><ul>
<li class="chapter" data-level="14.1" data-path="sensors.html"><a href="sensors.html#motion-sensors"><i class="fa fa-check"></i><b>14.1</b> Motion Sensors</a><ul>
<li class="chapter" data-level="" data-path="sensors.html"><a href="sensors.html#accessing-sensors"><i class="fa fa-check"></i>Accessing Sensors</a></li>
<li class="chapter" data-level="" data-path="sensors.html"><a href="sensors.html#composite-sensors"><i class="fa fa-check"></i>Composite Sensors</a></li>
</ul></li>
<li class="chapter" data-level="14.2" data-path="sensors.html"><a href="sensors.html#rotation"><i class="fa fa-check"></i><b>14.2</b> Rotation</a><ul>
<li class="chapter" data-level="" data-path="sensors.html"><a href="sensors.html#coordinates"><i class="fa fa-check"></i>Coordinates</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="15" data-path="graphics.html"><a href="graphics.html"><i class="fa fa-check"></i><b>15</b> Graphics and Touch</a><ul>
<li class="chapter" data-level="15.1" data-path="graphics.html"><a href="graphics.html#drawing-graphics"><i class="fa fa-check"></i><b>15.1</b> Drawing Graphics</a><ul>
<li class="chapter" data-level="" data-path="graphics.html"><a href="graphics.html#custom-views"><i class="fa fa-check"></i>Custom Views</a></li>
<li class="chapter" data-level="" data-path="graphics.html"><a href="graphics.html#surfaceviews"><i class="fa fa-check"></i>SurfaceViews</a></li>
</ul></li>
<li class="chapter" data-level="15.2" data-path="graphics.html"><a href="graphics.html#touch-and-gestures"><i class="fa fa-check"></i><b>15.2</b> Touch and Gestures</a><ul>
<li class="chapter" data-level="" data-path="graphics.html"><a href="graphics.html#advanced-gestures"><i class="fa fa-check"></i>Advanced Gestures</a></li>
</ul></li>
<li class="chapter" data-level="15.3" data-path="graphics.html"><a href="graphics.html#property-animation"><i class="fa fa-check"></i><b>15.3</b> Property Animation</a></li>
</ul></li>
<li class="part"><span><b>II Additional Topics (Labs)</b></span></li>
<li class="chapter" data-level="16" data-path="styles-themes.html"><a href="styles-themes.html"><i class="fa fa-check"></i><b>16</b> Styles & Themes</a><ul>
<li class="chapter" data-level="16.1" data-path="styles-themes.html"><a href="styles-themes.html#defining-styles"><i class="fa fa-check"></i><b>16.1</b> Defining Styles</a><ul>
<li class="chapter" data-level="" data-path="styles-themes.html"><a href="styles-themes.html#style-inheritance"><i class="fa fa-check"></i>Style Inheritance</a></li>
<li class="chapter" data-level="" data-path="styles-themes.html"><a href="styles-themes.html#built-in-styles"><i class="fa fa-check"></i>Built-in Styles</a></li>
<li class="chapter" data-level="" data-path="styles-themes.html"><a href="styles-themes.html#styles-for-text-views"><i class="fa fa-check"></i>Styles for Text Views</a></li>
</ul></li>
<li class="chapter" data-level="16.2" data-path="styles-themes.html"><a href="styles-themes.html#themes"><i class="fa fa-check"></i><b>16.2</b> Themes</a><ul>
<li class="chapter" data-level="" data-path="styles-themes.html"><a href="styles-themes.html#material-themes"><i class="fa fa-check"></i>Material Themes</a></li>
<li class="chapter" data-level="" data-path="styles-themes.html"><a href="styles-themes.html#theme-attributes"><i class="fa fa-check"></i>Theme Attributes</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="styles-themes.html"><a href="styles-themes.html#resources-2"><i class="fa fa-check"></i>Resources</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="fragment-viewpager.html"><a href="fragment-viewpager.html"><i class="fa fa-check"></i><b>17</b> Fragments: ViewPager</a><ul>
<li class="chapter" data-level="17.1" data-path="fragment-viewpager.html"><a href="fragment-viewpager.html#define-a-searchfragment"><i class="fa fa-check"></i><b>17.1</b> Define a SearchFragment</a></li>
<li class="chapter" data-level="17.2" data-path="fragment-viewpager.html"><a href="fragment-viewpager.html#add-the-viewpager-and-adapter"><i class="fa fa-check"></i><b>17.2</b> Add the ViewPager and Adapter</a></li>
<li class="chapter" data-level="17.3" data-path="fragment-viewpager.html"><a href="fragment-viewpager.html#add-user-interaction"><i class="fa fa-check"></i><b>17.3</b> Add User Interaction</a></li>
</ul></li>
<li class="chapter" data-level="18" data-path="bluetooth.html"><a href="bluetooth.html"><i class="fa fa-check"></i><b>18</b> Bluetooth</a></li>
<li class="chapter" data-level="19" data-path="maps.html"><a href="maps.html"><i class="fa fa-check"></i><b>19</b> Maps</a><ul>
<li class="chapter" data-level="19.1" data-path="maps.html"><a href="maps.html#create-a-map-activity"><i class="fa fa-check"></i><b>19.1</b> Create a Map Activity</a><ul>
<li class="chapter" data-level="" data-path="maps.html"><a href="maps.html#getting-an-api-key"><i class="fa fa-check"></i>Getting an API Key</a></li>
<li><a href="maps.html#the-supportmapfragment">The <code>SupportMapFragment</code></a></li>
</ul></li>
<li class="chapter" data-level="19.2" data-path="maps.html"><a href="maps.html#specifying-the-user-interface"><i class="fa fa-check"></i><b>19.2</b> Specifying the User Interface</a></li>
<li class="chapter" data-level="19.3" data-path="maps.html"><a href="maps.html#markers-and-drawings"><i class="fa fa-check"></i><b>19.3</b> Markers and Drawings</a><ul>
<li class="chapter" data-level="" data-path="maps.html"><a href="maps.html#drawing-shapes"><i class="fa fa-check"></i>Drawing Shapes</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="20" data-path="memory.html"><a href="memory.html"><i class="fa fa-check"></i><b>20</b> Memory Management</a><ul>
<li class="chapter" data-level="20.1" data-path="memory.html"><a href="memory.html#memory-allocation"><i class="fa fa-check"></i><b>20.1</b> Memory Allocation</a></li>
<li class="chapter" data-level="20.2" data-path="memory.html"><a href="memory.html#the-memory-monitor"><i class="fa fa-check"></i><b>20.2</b> The Memory Monitor</a><ul>
<li class="chapter" data-level="" data-path="memory.html"><a href="memory.html#garbage-collection"><i class="fa fa-check"></i>Garbage Collection</a></li>
</ul></li>
<li class="chapter" data-level="20.3" data-path="memory.html"><a href="memory.html#memory-leaks"><i class="fa fa-check"></i><b>20.3</b> Memory Leaks</a></li>
</ul></li>
<li class="chapter" data-level="21" data-path="multi-touch.html"><a href="multi-touch.html"><i class="fa fa-check"></i><b>21</b> Multi-Touch</a><ul>
<li class="chapter" data-level="21.1" data-path="multi-touch.html"><a href="multi-touch.html#identifying-fingers"><i class="fa fa-check"></i><b>21.1</b> Identifying Fingers</a></li>
<li class="chapter" data-level="21.2" data-path="multi-touch.html"><a href="multi-touch.html#drawing-touches"><i class="fa fa-check"></i><b>21.2</b> Drawing Touches</a></li>
<li class="chapter" data-level="21.3" data-path="multi-touch.html"><a href="multi-touch.html#moving-fingers"><i class="fa fa-check"></i><b>21.3</b> Moving Fingers</a></li>
<li class="chapter" data-level="21.4" data-path="multi-touch.html"><a href="multi-touch.html#other-multi-touch-gestures"><i class="fa fa-check"></i><b>21.4</b> Other Multi-Touch Gestures</a></li>
</ul></li>
<li class="appendix"><span><b>Appendix</b></span></li>
<li class="chapter" data-level="A" data-path="java-review.html"><a href="java-review.html"><i class="fa fa-check"></i><b>A</b> Java Review</a><ul>
<li class="chapter" data-level="A.1" data-path="java-review.html"><a href="java-review.html#building-apps-with-gradle"><i class="fa fa-check"></i><b>A.1</b> Building Apps with Gradle</a></li>
<li class="chapter" data-level="A.2" data-path="java-review.html"><a href="java-review.html#class-basics"><i class="fa fa-check"></i><b>A.2</b> Class Basics</a></li>
<li class="chapter" data-level="A.3" data-path="java-review.html"><a href="java-review.html#inheritance"><i class="fa fa-check"></i><b>A.3</b> Inheritance</a></li>
<li class="chapter" data-level="A.4" data-path="java-review.html"><a href="java-review.html#interfaces"><i class="fa fa-check"></i><b>A.4</b> Interfaces</a></li>
<li class="chapter" data-level="A.5" data-path="java-review.html"><a href="java-review.html#polymorphism"><i class="fa fa-check"></i><b>A.5</b> Polymorphism</a></li>
<li class="chapter" data-level="A.6" data-path="java-review.html"><a href="java-review.html#abstract-methods-and-classes"><i class="fa fa-check"></i><b>A.6</b> Abstract Methods and Classes</a></li>
<li class="chapter" data-level="A.7" data-path="java-review.html"><a href="java-review.html#generics"><i class="fa fa-check"></i><b>A.7</b> Generics</a></li>
<li class="chapter" data-level="A.8" data-path="java-review.html"><a href="java-review.html#nested-classes"><i class="fa fa-check"></i><b>A.8</b> Nested Classes</a></li>
</ul></li>
<li class="chapter" data-level="B" data-path="java-swing.html"><a href="java-swing.html"><i class="fa fa-check"></i><b>B</b> Java Swing Framework</a><ul>
<li class="chapter" data-level="B.1" data-path="java-swing.html"><a href="java-swing.html#events"><i class="fa fa-check"></i><b>B.1</b> Events</a></li>
<li class="chapter" data-level="B.2" data-path="java-swing.html"><a href="java-swing.html#layouts-and-composites"><i class="fa fa-check"></i><b>B.2</b> Layouts and Composites</a></li>
</ul></li>
<li class="chapter" data-level="C" data-path="publishing.html"><a href="publishing.html"><i class="fa fa-check"></i><b>C</b> Publishing</a><ul>
<li class="chapter" data-level="C.1" data-path="publishing.html"><a href="publishing.html#signing-an-app"><i class="fa fa-check"></i><b>C.1</b> Signing an App</a><ul>
<li><a href="publishing.html#release-.apk">Release <code>.apk</code></a></li>
</ul></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Android Development: Lecture Notes</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="data-views" class="section level1">
<h1><span class="header-section-number">Lecture 4</span> Data-Driven Views</h1>
<p><a href="resources-and-layouts.html#resources-and-layouts">A previous lecture</a> discussed how to use Views to display content and support user interaction. This lecture extends those concepts and presents techniques for creating <strong>data-driven views</strong>—views that can <em>dynamically</em> present a data model in the form of a <em>scrollable list</em>. It also explains how to access data on the web using the <a href="https://developer.android.com/training/volley/index.html">Volley</a> library. Overall, this process demonstrates a common way to connect the user interface for the app (defined as XML) with logic and data controls (defined in Java), following the <strong>Model-View-Controller</strong> architecture found throughout the Android framework.</p>
<p class="alert alert-info">
This lecture references code found at <a href="https://github.com/info448/lecture04-lists" class="uri">https://github.com/info448/lecture04-lists</a>.
</p>
<div id="listviews-and-adapters" class="section level2">
<h2><span class="header-section-number">4.1</span> ListViews and Adapters</h2>
<p>In particular, this lecture discussed how to utilize a <a href="https://developer.android.com/guide/topics/ui/layout/listview.html">ListView</a><a href="#fn12" class="footnoteRef" id="fnref12"><sup>12</sup></a>, which is a <code>ViewGroup</code> that displays a scrollable list of items! A <code>ListView</code> is basically a <code>LinearLayout</code> inside of a <code>ScrollView</code> (which is a <code>ViewGroup</code> that can be scrolled). Each element within the LinearLayout is another <code>View</code> (usually a Layout) representing a particular item in a list.</p>
<p>But the <code>ListView</code> does extra work beyond just nesting Views: it keeps track of what items are already displayed on the screen, inflating only the visible items (plus a few extra on the top and bottom as buffers). Then as the user scrolls, the ListView takes the disappearing views and <em>recycles</em> them (altering their content, but not re-inflating from scratch) in order to reuse them for the new items that appear. This lets it save memory, provide better performance, and overall work more smoothly. See <a href="https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView#row-view-recycling">this tutorial</a> for diagrams and further explanation of this recycling behavior.</p>
<ul>
<li>Note that a more advanced and flexible version of this behavior is offered by the <a href="https://developer.android.com/guide/topics/ui/layout/recyclerview.html"><code>RecyclerView</code></a> class, which works in mostly the same way but requires a few extra steps to set up. See also <a href="https://developer.android.com/training/material/lists-cards.html">this guide</a> for more details.</li>
</ul>
<p>The <code>ListView</code> control uses a <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"><strong>Model-View-Controller (MVC)</strong></a> architecture. This is a design pattern common to UI systems which organizes programs into three parts:</p>
<ol style="list-style-type: decimal">
<li>The <strong>Model</strong>, which is the data or information in the system</li>
<li>The <strong>View</strong>, which is the display or representation of that data</li>
<li>The <strong>Controller</strong>, which acts as an intermediary between the Model and View and hooks them together.</li>
</ol>
<p>The MVC pattern can be found all over Android. At a high level, the resources provide <em>models</em> and <em>views</em> (separately), while the Java Activities act as <em>controllers</em>.</p>
<p class="alert alert-info">
<em>Fun fact</em>: The Model-View-Controller pattern was originally developed as part of the <a href="http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html">Smalltalk</a> language, which was the first Object-Oriented language!
</p>
<p>Thus in order to utilize a <code>ListView</code>, we’ll have some data to be displayed (the <strong>model</strong>), the <strong>views</strong> (layouts) to be shown, and the <code>ListView</code> itself will connect these together act as the <strong>controller</strong>. Specifically, the <code>ListView</code> is a subclass of <a href="https://developer.android.com/reference/android/widget/AdapterView.html"><code>AdapterView</code></a>, which is a View backed by a data source—the <code>AdapterView</code> exists to hook the View and the data together (just as a controller should).</p>
<ul>
<li>There are other <code>AdapterViews</code> as well. For example, <a href="https://developer.android.com/guide/topics/ui/layout/gridview.html"><code>GridView</code></a> works exactly the same way as a <code>ListView</code>, but lays out items in a scrollable grid rather than a scrollable list.</li>
</ul>
<p>In order to use a <code>ListView</code>, we need to get the pieces in place:</p>
<ol style="list-style-type: decimal">
<li><p>First we specify the <strong>model</strong>: some raw data. We will start with a simple list of Strings, filling it with placeholder data:</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="kw">val</span> <span class="va">data</span> = mutableListOf<<span class="kw">String</span>>()
<span class="cf">for</span>(i <span class="kw">in</span> <span class="dv">99</span> downTo <span class="dv">1</span>){
<span class="kw">data</span>.add(i.toString() + <span class="st">" bottles of beer on the wall"</span>)
} </code></pre></div>
<p>While we normally should define such hard-coded data as <a href="https://developer.android.com/guide/topics/resources/string-resource.html#StringArray">an XML resource</a>, we’ll create it dynamically for testing (and to make it changeable later!). Using a List instead of an Array makes it easier to construct (and works the same way).</p></li>
<li><p>Next we specify the <strong>view</strong>: a <code>View</code> to show for each datum in the list. Define an XML layout resource for that (<code>list_item</code> is a good name and a common idiom).</p>
<p>We don’t really need to specify a full Layout (though we could if we wanted): just a basic <code>TextView</code> will suffice. Have the width <code>match_parent</code> and the height <code>wrap_content</code>. <em>Don’t forget an <code>id</code>!</em></p>
<div class="sourceCode"><pre class="sourceCode xml"><code class="sourceCode xml"><span class="co"><!-- need to include the XML namespace (xmlns) so the `android` namespace validates --></span>
<span class="kw"><TextView</span><span class="ot"> xmlns:android=</span><span class="st">"http://schemas.android.com/apk/res/android"</span>
<span class="ot"> android:id=</span><span class="st">"@+id/txtItem"</span>
<span class="ot"> android:layout_width=</span><span class="st">"match_parent"</span>
<span class="ot"> android:layout_height=</span><span class="st">"wrap_content"</span> <span class="kw">/></span></code></pre></div>
<p>To make it look better, you can specify <code>android:minHeight="?android:attr/listPreferredItemHeight"</code> (using the framework’s preferred height for lists), and some <code>center_vertical</code> gravity. The <code>android:lines</code> property is also useful if you need more space.</p></li>
<li><p>Finally, we specify the <strong>controller</strong>: the <code>ListView</code> itself. Add that item to the Activity’s Layout resource (<em>practice</em>: what should its dimensions be?)</p></li>
</ol>
<p>To finish the controller <code>ListView</code>, we ned to provide it with an <a href="https://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews"><code>Adapter</code></a><a href="#fn13" class="footnoteRef" id="fnref13"><sup>13</sup></a> which will connect the <em>model</em> to the <em>view</em>. The Adapter does the “translation” work between model and view, performing a mapping from data types (e.g., a <code>String</code>) and View types (e.g., a <code>TextView</code>).</p>
<p>Specifically, we will use an <a href="https://developer.android.com/reference/android/widget/ArrayAdapter.html"><code>ArrayAdapter</code></a>, which is one of the simplest Adapters to use (and because we have an array of data!) An <code>ArrayAdapter</code> creates Views by calling <code>.toString()</code> on each item in the array, and setting that <code>String</code> as the content of a <code>TextView</code>!</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="co">//kotlin</span>
<span class="kw">val</span> <span class="va">adapter</span> = ArrayAdapter<<span class="kw">String</span>>(<span class="kw">this</span>,
R.layout.list_item_layout, R.layout.list_item_txtView, myStringArray);</code></pre></div>
<ul>
<li>Note the parameters of the constructor: a <code>Context</code> to access resources, the layout resource to use for each item, the <code>TextView</code> within that layout (the target of the mapping), and the data array (the source of the mapping). Also note that this instance utilizes <a href="java-review.html#generics"><em>generics</em></a>: we’re using an array of <code>Strings</code> (as opposed to an array of <code>Dogs</code> or some other type).</li>
</ul>
<p>We acquire a reference to the <code>ListView</code> with <code>findViewById()</code>, and call <code>ListView#setAdapter()</code> to attach the adapter to that controller.</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="co">//kotlin </span>
<span class="kw">val</span> <span class="va">listView</span> = findViewById<ListView>(R.id.list_view)
listView.setAdapter(adapter)</code></pre></div>
<p>And that’s all that is needed to create a scrollable list of data! To track the process: the Adapter will go through each item in the <em>model</em>, and “translate” that item into the contents of a View. These Views will then be displayed in a scrollable list.</p>
<p>Each item in this list is selectable (can be given an <code>onClick</code> callback). This allows us to click on any item in order to (for example) get more details about the item. Utilize the <code>AdapterView#setOnItemClickListener(OnItemClickListener)</code> function to register the callback.</p>
<ul>
<li>The <code>position</code> parameter in the <code>onItemClick()</code> callback is the index of the item which was clicked. Use <code>(Type)parent.getItemAtPosition(position)</code> to access the data value associated with that View.</li>
</ul>
<p>Additionally, each item does have an individual layout, so you can customize these appearances (e.g., if our layout also wanted to include pictures). See <a href="https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView#row-view-recycling">this tutorial</a> for an example on making a custom adapter to fill in multiple <code>Views</code> with data from a list!</p>
<div class="alert alert-info">
<p>
And remember, a <code>GridView</code> is basically the same thing (in fact, we can just change over that and have everything work, if we use <em>polymorphism</em>!) Note that the data type for the <code>AdapterView</code> is a little thorny if you want to be generic about it:
</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="kw">val</span> <span class="va">adapterView</span> = findViewById<AdapterView<ArrayAdapter<<span class="kw">String</span>>>>(R.id.list_view)</code></pre></div>
</div>
<!--### **break**-->
</div>
<div id="networking-with-volley" class="section level2">
<h2><span class="header-section-number">4.2</span> Networking with Volley</h2>
<p>A list with hard-coded data isn’t very useful. It would be better if that data could be accessed dynamically, such as downloaded from the Internet!</p>
<p>There are a couple of different ways to programmatically send network requests from an Android application. The “lowest level” is to utilize the <a href="https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html"><code>HttpURLConnection</code></a> API. With this API, you call methods to open a connection to a URL and then to send an HTTP Request to that location. The response is returned as an <a href="https://developer.android.com/reference/java/io/InputStream.html"><code>InputStream</code></a>, which you need to “read” byte by byte in order to reconstruct the received data (e.g., to make it back into a String). See <a href="https://developer.android.com/training/basics/network-ops/connecting.html#download">this example</a> for details.</p>
<p>While this technique is effective, it can be tedious to implement. Moreover, downloading network data can take a while—and these network method calls are synchronous and <strong>blocking</strong>, so will prevent other code from running while it downloads—including code that enables the user interface! Such block will lead to the infamous <em>“Application not responding” (ANR)</em> error. While it is possible to send such requests asynchronously on a <em>background thread</em> to avoid blocking, that requires additional overhead work. See the <a href="services.html#services">Services Lecture</a> for more details.</p>
<p>To solve these problems with less work, it can be be more effective to utilize an <strong>external library</strong> that lets us abstract away this process and just talk about making network requests and getting data back from them. (This is similar to how in web programming the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"><code>fetch</code> API</a> abstracts the opaque <code>XMLHttpRequest</code> object). In particular, this lecture will introduce the <a href="https://developer.android.com/training/volley/index.html"><strong>Volley</strong></a> library, which is an external library developed and maintained by Google. It provides a number of benefits over a more “manual” approach, including handling multiple concurrent requests and enabling the caching of downloaded data. It also causes network requests to be handled asynchronously on a background thread without any additional effort!</p>
<p class="alert alert-info">
Volley’s main “competitor” is the <a href="http://square.github.io/retrofit/">Retrofit</a> library produced by <a href="http://square.github.io/">Square</a>. While Retrofit is usually faster at processing downloaded data, Volley has built-in support for handling images (which will be useful in the future), and has a slightly more straightforward interface.
</p>
<div id="using-volley" class="section level3 unnumbered">
<h3>Using Volley</h3>
<p>Because Volley is an external library (it isn’t built into the Android framework), you need to explicitly download and include it in your project. Luckily, we can use the <em>Gradle</em> build system to do this for us by listing Volley as a <strong>dependency</strong> for the project. Inside the <em>app-level</em> <code>build.gradle</code> file, add the following line inside the <code>dependencies</code> list:</p>
<pre class="gradle"><code>compile 'com.android.volley:volley:1.0.0'</code></pre>
<p>This will tell Android that it should download and include version <code>1.0.0</code> of the Volley library when it builds the app. Hit the “Sync” button to update and rebuild the project.</p>
<ul>
<li>External libraries will be built into your app, increasing the file size of the compiled <code>.apk</code> (there is more code!). Though this won’t cause any problems for us, it’s worth keeping in mind as you design new apps.</li>
</ul>
<p>Once you have included Volley as a dependency, you will have access to the <a href="http://afzaln.com/volley/">classes and API</a> to use in your code.</p>
<p>In order to request data with Volley, you will need to instantiate a <a href="https://afzaln.com/volley/com/android/volley/Request.html"><code>Request</code></a> object based on the type of data you will be downloading: a <code>StringRequest</code> for downloading text data, a <code>JsonRequest</code> for downloading JSON formatted data, or an <code>ImageRequest</code> for downloading images.</p>
<p>The constructor for <code>StringRequest</code>, for example, takes 4 arguments:</p>
<div class="list-condensed">
<ol style="list-style-type: decimal">
<li>A constant representing the HTTP method (verb) to use. E.g., <code>Request.Method.GET</code></li>
<li>The URL to send the request to (as a String)</li>
<li>A <code>Response.Listener</code> object, which defines a callback function to be executed when the response is received.</li>
<li>A <code>Response.ErrorListener</code> object, which defines a callback function to be executed in case of an error.</li>
</ol>
</div>
<p>Because the last two <em>listener</em> objects are usually defined with anonymous classes, this can make the Request constructor look more complicated than it is (though Kotlin’s use of lambdas helps):</p>
<div class="sourceCode"><pre class="sourceCode java"><code class="sourceCode java"><span class="co">//java</span>
<span class="co">//silly example: get 20 random dinosaur names</span>
<span class="bu">String</span> url = <span class="st">"http://dinoipsum.herokuapp.com/api/?format=text&words=20&paragraphs=1"</span>;
<span class="bu">Request</span> myRequest = <span class="kw">new</span> <span class="fu">StringRequest</span>(<span class="bu">Request</span>.<span class="fu">Method</span>.<span class="fu">GET</span>, url,
<span class="kw">new</span> <span class="bu">Response</span>.<span class="fu">Listener</span><<span class="bu">String</span>>() {
<span class="kw">public</span> <span class="dt">void</span> <span class="fu">onResponse</span>(<span class="bu">String</span> response) {
Log.<span class="fu">v</span>(TAG, response);
}
}, <span class="kw">new</span> <span class="bu">Response</span>.<span class="fu">ErrorListener</span>() {
<span class="at">@Override</span>
<span class="kw">public</span> <span class="dt">void</span> <span class="fu">onErrorResponse</span>(VolleyError error) {
Log.<span class="fu">e</span>(TAG, error.<span class="fu">toString</span>());
}
});</code></pre></div>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="co">//kotlin</span>
<span class="kw">val</span> <span class="va">request</span> = StringRequest(Request.Method.GET, urlString,
<span class="co">//callback for success</span>
Response.Listener { response ->
Log.v(TAG, response)
},
<span class="co">//callback for failure</span>
Response.ErrorListener { error ->
Log.e(TAG, error.toString())
})</code></pre></div>
<p>(Also note that the <code>Response.Listener</code> is a <em>generic</em> class, in which we specify the format we’re expecting the response to come back in. This is <code>String</code> for a <code>StringRequest</code>, but would be e.g., <code>JSONObject</code> for a <code>JsonObjectRequest</code>). Kotlin handles some of this for us.</p>
<p>In order to actually <em>send</em> this Request, you need a <a href="https://afzaln.com/volley/com/android/volley/RequestQueue.html"><code>RequestQueue</code></a>, which acts like a “dispatcher” and handles sending out the Requests on background threads and otherwise managing the network operations. We create a dispatcher with default parameters (for networking and caching) using the <code>Volley.newRequestQueue()</code> factory method:</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="co">//kotlin</span>
<span class="kw">val</span> <span class="va">requestQueue</span>: requestQueue = Volley.newRequestQueue(<span class="kw">this</span>.applicationContext);</code></pre></div>
<p>The factory method takes in a Context for managing the cache; the best practice is to use the application’s Context so it isn’t dependent on a single Activity.</p>
<p>Once you have a RequestQueue, you can add your request to that in order to “send” it:</p>
<div class="sourceCode"><pre class="sourceCode java"><code class="sourceCode java">requestQueue.<span class="fu">add</span>(myRequest);</code></pre></div>
<p class="alert alert-warning">
If you test this code, you’ll notice that it doesn’t work! The program will crash with a <code>SecurityException</code>.
</p>
<p>As a <a href="https://developer.android.com/guide/topics/permissions/index.html">security feature</a>, Android apps by default have very limited access to the overall operating system (e.g., to do anything other than show a layout). An app can’t use the Internet (which might consume people’s data plans!) without explicit permission from the user. This permission is given by the user at <em>install time</em>.</p>
<p>In order to get permission, the app needs to ask for it (“Mother may I…?”). We do that by declaring that the app uses the Internet in the <code>AndroidManifest.xml</code> file (which has all the details of our app!)</p>
<div class="sourceCode"><pre class="sourceCode xml"><code class="sourceCode xml"><span class="kw"><uses-permission</span><span class="ot"> android:name=</span><span class="st">"android.permission.INTERNET"</span><span class="kw">/></span>
<span class="co"><!-- put this ABOVE the <application> tag --></span></code></pre></div>
<p>Note that Marshmallow introduced a <a href="https://developer.android.com/training/permissions/requesting.html">new security model</a> in which users grant permissions at <em>run-time</em>, not install time, and can revoke permissions whenever they want. To handle this, you need to add code to request “dangerous” permissions (like Location, Phone, or SMS access) each time you use it. This process is discussed in the <a href="files-and-permissions.html#files-and-permissions">Files and Permissions</a> Lecture. Using the Internet is <em>not</em> a dangerous permission, so only requires the permission declaration in the Manifest.</p>
<p>Once we’ve requested permission (and have been granted that permission by virtue of the user installing our application), we can finally connect to the Internet to download data. We can log out the request results to prove we got it!</p>
<p>Of course, we’d like to display that data on the screen (rather than just log it out). That is, we want to put it into the ListView, meaning that we need to feed it back into the Adapter (which works to populate the Views).</p>
<ul>
<li>First, clear out any previous data items in the adapter using <code>adapter.clear()</code>.</li>
<li>Then use <code>adapter.add()</code> or (<code>adapter.addAll()</code>) to add each of the new data items to the Adapter’s model! Note that you may need to do data parsing on the response body, such as splitting a String or constructing an <code>array</code> or <code>ArrayList</code> out of JSON data.</li>
<li>You can call <code>notifyDataSetChanged()</code> on the Adapter to make sure that the View knows the data has changed, but this method is already called by the <code>.add()</code> method so isn’t necessary in this situation.</li>
</ul>
<p class="alert alert-info">
You can use the <code>JsonObjectRequest</code> class to download data as a JSON Object rather than a raw String. JSON Objects and Arrays can be converted into Java Objects/Arrays using two classes: <a href="http://developer.android.com/reference/org/json/JSONObject.html"><code>JSONObject</code></a> and <a href="http://developer.android.com/reference/org/json/JSONArray.html"><code>JSONArray</code></a>. The constructors for each of these classes take a JSON String, and you can call the <code>getJSONArray(key)</code> and <code>getJSONObject(key)</code> in order to get nested objects and arrays from inside a <code>JSONObject</code> or <code>JSONArray</code>.
</p>
</div>
<div id="requestqueue-singletons" class="section level3 unnumbered">
<h3>RequestQueue Singletons</h3>
<p>If you are going to make multiple network requests for your application (which you usually will for anything of a reasonable size), it is wasteful to repeatedly instantiate new <code>RequestQueue</code> objects—these can take up significant memory and step on each others toes.</p>
<p>Instead, the best practice is to use the <a href="https://developer.android.com/training/volley/requestqueue.html#singleton">Singleton Design Pattern</a> to ensure that your entire application only uses a <em>single</em> RequestQueue.</p>
<p>To do this, you will want to create an entire class (e.g., <code>VolleyService</code>) that will only ever be instantiated once (it will be a “singleton”). Since the Volley <code>RequestQueue</code> is controlled by this singleton, it means there will only ever be one <code>RequestQueue</code>.</p>
<div class="sourceCode"><pre class="sourceCode java"><code class="sourceCode java"><span class="co">//java</span>
<span class="kw">public</span> <span class="kw">class</span> RequestSingleton { <span class="co">//make static if an inner class!</span>
<span class="co">//the single instance of this singleton</span>
<span class="kw">private</span> <span class="dt">static</span> RequestSingleton instance;
<span class="kw">private</span> RequestQueue requestQueue = <span class="kw">null</span>; <span class="co">//the singleton's RequestQueue</span>
<span class="co">//private constructor; cannot instantiate directly</span>
<span class="kw">private</span> <span class="fu">RequestSingleton</span>(<span class="bu">Context</span> ctx){
<span class="co">//create the requestQueue</span>
<span class="kw">this</span>.<span class="fu">requestQueue</span> = Volley.<span class="fu">newRequestQueue</span>(ctx.<span class="fu">getApplicationContext</span>());
}
<span class="co">//call this "factory" method to access the Singleton</span>
<span class="kw">public</span> <span class="dt">static</span> RequestSingleton <span class="fu">getInstance</span>(<span class="bu">Context</span> ctx) {
<span class="co">//only create the singleton if it doesn't exist yet</span>
<span class="kw">if</span>(instance == <span class="kw">null</span>){
instance = <span class="kw">new</span> <span class="fu">RequestSingleton</span>(ctx);
}
<span class="kw">return</span> instance; <span class="co">//return the singleton object</span>
}
<span class="co">//get queue from singleton for direct action</span>
<span class="kw">public</span> RequestQueue <span class="fu">getRequestQueue</span>() {
<span class="kw">return</span> <span class="kw">this</span>.<span class="fu">requestQueue</span>;
}
<span class="co">//convenience wrapper method</span>
<span class="kw">public</span> <T> <span class="dt">void</span> <span class="fu">add</span>(<span class="bu">Request</span><T> req) {
requestQueue.<span class="fu">add</span>(req);
}
}</code></pre></div>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="co">//kotlin</span>
<span class="kw">private</span> <span class="kw">class</span> VolleyService
<span class="kw">private</span> <span class="kw">constructor</span>(<span class="va">ctx</span>: <span class="dt">Context</span>) { <span class="co">//private constructor; cannot instantiate directly</span>
<span class="kw">companion</span> <span class="kw">object</span> { <span class="co">//to hold the shared instances</span>
<span class="kw">private</span> <span class="kw">var</span> <span class="va">instance</span>: VolleyService? = <span class="kw">null</span> <span class="co">//the single instance of this singleton</span>
<span class="co">//call this "factory" method to access the Singleton</span>
<span class="kw">fun</span> <span class="fu">getInstance</span>(<span class="va">ctx</span>: <span class="dt">Context</span>): <span class="dt">VolleyService</span> {
<span class="co">//only create the singleton if it doesn't exist yet</span>
<span class="cf">if</span> (instance == <span class="kw">null</span>) {
instance = VolleyService(ctx)
}
<span class="kw">return</span> instance <span class="kw">as</span> VolleyService <span class="co">//force casting</span>
}
}
<span class="co">//from Kotlin docs</span>
<span class="kw">val</span> <span class="va">requestQueue</span>: RequestQueue <span class="kw">by</span> lazy { <span class="co">//instantiate once needed</span>
Volley.newRequestQueue(ctx.applicationContext) <span class="co">//return the context-based requestQueue</span>
}
<span class="co">//convenience wrapper method</span>
<span class="kw">fun</span> <<span class="dt">T</span>> <span class="fu">add</span>(<span class="va">req</span>: <span class="dt">Request</span><<span class="va">T</span>>) {
requestQueue.add(req)
}
}</code></pre></div>
<p>See also the <a href="https://github.com/JetBrains/kotlin-examples/tree/master/gradle/android-volley">JetBrains Kotlin Demo</a> of Volley for further examples</p>
<p>This structure will let you make multiple network requests from multiple components of your app, but without trying to have multiple “dispatchers” taking up memory.</p>
</div>
<div id="downloading-images" class="section level3 unnumbered">
<h3>Downloading Images</h3>
<p>In addition to downloading text or JSON data via HTTP requests, Volley is also able to support downloading <em>images</em> to be shown in your app.</p>
<p>In general, handling images in Android is a difficult task. Images are large files (often multiple megabytes in size) that may require extensive and lingering data transfer to download and require processor-intensive decoding in order to be displayed. Since mobile devices are <em>resource constrained</em> (particularly in memory), trying to download and display lots of images—say in a scrollable list—can quickly cause problems. See <a href="https://developer.android.com/topic/performance/graphics/index.html">Handling Bitmaps</a> and <a href="https://developer.android.com/topic/performance/graphics/load-bitmap.html">Loading Large Bitmaps Efficiently</a> for some examples of the complexity needed to work with images.</p>
<p>Volley provides some support to make downloading and processing images easier. In particular, it provides built-in support for <em>network management</em> (so that data transfers are most efficiently optimized), <em>caching</em> (so you don’t try to download the same image twice), and for easily <em>displaying</em> network-loaded images.</p>
<p class="alert alert-info">
The other popular image-management libraries are <a href="https://github.com/bumptech/glide">Glide</a>, Square’s <a href="http://square.github.io/picasso/">Picasso</a>, and Facebook’s <a href="https://github.com/facebook/fresco">Fresco</a>. Google recommends using Glide for doing complex image work. However, if Volley’s image loading is sufficient for your task, that allows you to only need to work with a single library and networking queue.
</p>
<p>In order to effectively download images with Volley, you need to set up an <a href="https://afzaln.com/volley/com/android/volley/toolbox/ImageLoader.html"><code>ImageLoader</code></a>. This object will handling downloading remote images as well as <em>caching</em> them for the future.</p>
<p>To instantiate an <code>ImageLoader</code>, you need to provide a <code>RequestQueue</code> as well as an <code>ImageCache</code> object that represents how image data should be cached (e.g., in memory, on disk, etc.). The Volley documentation suggests using a <code>LruCache</code> object for caching to memory (though you can use a <code>DiskBasedCache</code> as well):</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="co">//kotlin</span>
<span class="co">//instantiate the image loader (from Kotlin docs)</span>
<span class="co">//params are the requestQueue and the Cache</span>
<span class="kw">val</span> <span class="va">imageLoader</span>: ImageLoader <span class="kw">by</span> lazy { <span class="co">//only instantiate when needed</span>
ImageLoader(requestQueue,
<span class="kw">object</span> : <span class="dt">ImageLoader</span>.<span class="dt">ImageCache</span> { <span class="co">//anonymous cache object</span>
<span class="kw">private</span> <span class="kw">val</span> <span class="va">cache</span> = LruCache<<span class="kw">String</span>, Bitmap>(<span class="dv">20</span>)
<span class="kw">override</span> <span class="kw">fun</span> <span class="fu">getBitmap</span>(<span class="va">url</span>: <span class="dt">String</span>): <span class="dt">Bitmap?</span> {
<span class="kw">return</span> cache.<span class="kw">get</span>(url)
}
<span class="kw">override</span> <span class="kw">fun</span> <span class="fu">putBitmap</span>(<span class="va">url</span>: <span class="dt">String</span>, <span class="va">bitmap</span>: <span class="dt">Bitmap</span>) {
cache.put(url, bitmap)
}
})
}</code></pre></div>
<ul>
<li>It’s a good idea to make this <code>ImageLoader</code> an instance variable of the <code>VolleyService</code>.</li>
</ul>
<p>Once you have the <code>ImageLoader</code>, you can use it to download an image by calling it’s <a href="https://afzaln.com/volley/com/android/volley/toolbox/ImageLoader.html#get(java.lang.String, com.android.volley.toolbox.ImageLoader.ImageListener)"><code>get()</code></a> method, specifying a callback listener that will be executed when the image is finished downloading.</p>
<p>However, you almost always want to download an image in order to display it. Volley makes this easy by providing a customized View called <a href="https://afzaln.com/volley/com/android/volley/toolbox/NetworkImageView.html"><code>NetworkImageView</code></a>. A <code>NetworkImageView</code> is able to handle the downloading of its source image on its own, integrating that process into the Activity’s lifecycle (e.g., so it won’t download when the View isn’t displayed).</p>
<p>You declare a <code>NetworkImageView</code> in the layout XML in the same way you would specify an <code>ImageView</code>:</p>
<div class="sourceCode"><pre class="sourceCode xml"><code class="sourceCode xml"><span class="kw"><com.android.volley.toolbox.NetworkImageView</span>
<span class="ot"> android:id=</span><span class="st">"@+id/img_remote"</span>
<span class="ot"> android:layout_width=</span><span class="st">"wrap_content"</span>
<span class="ot"> android:layout_height=</span><span class="st">"wrap_content"</span>
<span class="ot"> android:scaleType=</span><span class="st">"fitXY"</span>
<span class="kw">/></span></code></pre></div>
<ul>
<li>The <a href="https://developer.android.com/reference/android/widget/ImageView.ScaleType.html"><code>android:scaleType</code></a> attribute indicates how the image should be scaled to fit the View.</li>
</ul>
<p>In order to download an image into this View, you call the <code>setImageUrl()</code> method on the View from within your Java, specify the image url to load into the View and the <code>ImageLoader</code> to use for this network access:</p>
<div class="sourceCode"><pre class="sourceCode kotlin"><code class="sourceCode kotlin"><span class="kw">val</span> <span class="va">imageView</span> = findViewById<NetworkImageView>(R.id.img_remote)
netView.setImageUrl(<span class="st">"https://ischool.uw.edu/fb-300x300.png"</span>, imageLoader);</code></pre></div>
<p>And that will let you download and show images from the Internet (without needing to make them into a <code>drawable</code> resource)!</p>
<!-- ## RecyclerView
The `ListView` is an effective way of creating scrollable lists of data. However, creating lists that run -->
<!-- Ran out of time
Should show shorter video.
RecyclerView wasn't clear; could take more time??
Skipped cards (fine)
Fab/Snackbar fun
Skipped custom behavior (sad)
need to fix transition/fab bug... -->
</div>
</div>
</div>
<div class="footnotes">
<hr />
<ol start="12">
<li id="fn12"><p><a href="https://developer.android.com/guide/topics/ui/layout/listview.html" class="uri">https://developer.android.com/guide/topics/ui/layout/listview.html</a><a href="data-views.html#fnref12">↩</a></p></li>
<li id="fn13"><p><a href="https://developer.android.com/reference/android/widget/Adapter.html" class="uri">https://developer.android.com/reference/android/widget/Adapter.html</a><a href="data-views.html#fnref13">↩</a></p></li>
</ol>
</div>
</section>
</div>
</div>
</div>
<a href="activities.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="material-design.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": true,
"facebook": false,
"twitter": false,
"google": false,
"weibo": false,
"instapper": false,
"vk": false,
"all": ["github", "facebook", "twitter", "google"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/info448/book/edit/master/data-views.Rmd",
"text": "Edit"
},
"download": ["android-development.pdf", "android-development.epub"],
"toc": {
"collapse": "section",
"scroll_highlight": true
}
});
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML";
if (location.protocol !== "file:" && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>