kode ish1e3 – algoritma dan pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/w5-user...8...

1

Upload: others

Post on 17-Apr-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

1

Kode ISH3J4 – Pemrograman Aplikasi Bergerak

Pemrograman Mobile

Rahmat Fauzi, S.T.,M.T

Sistem Informasi – Fakultas Rekayasa Industri

Page 2: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

2

2

Sprint 1

Page 3: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

3

USER EXPERIENCE

User Interaction

3

Page 4: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

4

bit.ly/Video4SI4108

(Terakhir 23.59 Selasa, 18 Februari 2020)

4

Pengumpulan Praktikum

Page 5: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

5Let’s Practice

Open CodeLabs Google

5

Page 6: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

6

4.1 Buttons and clickable images

6

Page 7: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

7Contents

● User interaction● Buttons● Clickable images● Floating action button● Common gestures

7

Page 8: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

8

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

User interaction

8

Page 9: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

9Users expect to interact with apps

● Tapping or clicking, typing, using gestures, and talking

● Buttons perform actions

● Other UI elements enable data input and navigation

9

Page 10: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

10

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Buttons

10

Page 11: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

11Button

● View that responds to tapping (clicking) or pressing

● Usually text or visuals indicate what will happen when tapped

● State: normal, focused, disabled, pressed, on/off

11

Page 12: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

12Button image assets

1. Right-click app/res/drawable

2. Choose New > Image Asset

3. Choose Action Bar and Tab Items from drop down menu

4. Click the Clipart: image (the Android logo)

12

Experiment:2. Choose New > Vector Asset

Page 13: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

13Responding to button taps

● In your code: Use OnClickListener event listener.● In XML: use android:onClick attribute in the XML layout:

<Buttonandroid:id="@+id/button_send"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send"android:onClick="sendMessage" />

13

android:onClick

Presenter
Presentation Notes
A click event occurs when the user taps or clicks a button, or an image used as a button. The object notifies an event listener called OnClickListener, which is an interface in the View class. You can use the listener to respond to a click event. Android Studio provides a shortcut for setting up an OnClickListener for the clickable object in your Activity code, and for assigning a callback method: use the android:onClick attribute with the clickable object’s element in the XML layout. For example: <Button android:id="@+id/button_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" android:onClick="sendMessage" /> In this case, when a user clicks the button, the Android system calls the Activity’s sendMessage() method.
Page 14: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

14Setting listener with onClick callback

Button button = findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {

// Do something in response to button click}

});

14

Page 15: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

15

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Clickable images

15

Page 16: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

16ImageView● ImageView with android:onClick attribute

● Image for ImageView in app>src>main>res>drawable folder in project

16

Page 17: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

17Responding to ImageView taps

● In your code: Use OnClickListener event listener.● In XML: use android:onClick attribute in the XML layout:

<ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/donut_circle"android:onClick="orderDonut"/>

17

android:onClick

Presenter
Presentation Notes
A click event occurs when the user taps or clicks a button, or an image used as a button. The object notifies an event listener called OnClickListener, which is an interface in the View class. You can use the listener to respond to a click event. Android Studio provides a shortcut for setting up an OnClickListener for the clickable object in your Activity code, and for assigning a callback method: use the android:onClick attribute with the clickable object’s element in the XML layout. For example: <Button android:id="@+id/button_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" android:onClick="sendMessage" /> In this case, when a user clicks the button, the Android system calls the Activity’s sendMessage() method.
Page 18: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

18

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Floating action button

18

Page 19: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

19Floating Action Buttons (FAB)

● Raised, circular, floats above layout● Primary or "promoted" action for a screen● One per screen

For example:

Add Contact button in Contacts app

19

Presenter
Presentation Notes
Page 20: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

20

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Common Gestures

20

Page 21: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

21Touch Gestures

Touch gestures include:

● long touch● double-tap● fling● drag● scroll● pinch

21

Don’t depend on touch gestures for app's basic behavior!

Page 22: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

22

4.2 Input Controls

22

Page 23: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

23Contents

● Overview of input controls

● Freeform text and numbers

● Providing choices

23

Page 24: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

24

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Overview of input Controls

24

Page 25: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

25Accepting user input

● Freeform text and numbers: EditText (using keyboard)

● Providing choices: CheckBox, RadioButton, Spinner

● Switching on/off: Toggle, Switch

● Choosing value in range of values: SeekBar

25

Page 27: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

27

1. Use EditText for entering text using keyboard2. Use SeekBar for sliding left or right to a setting3. Combine CheckBox elements for choosing more than one

option4. Combine RadioButton elements into RadioGroup — user

makes only one choice5. Use Switch for tapping on or off6. Use Spinner for choosing a single item from a list

How input controls work

27

Page 28: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

28

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Freeform text and numbers

28

Page 29: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

29EditText for multiple lines of text

● EditText default● Alphanumeric keyboard● Suggestions appear● Tapping Return (Enter) key starts

new line

29

Return key

Page 30: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

30Customize with inputType

● Set in Attributes pane of layout editor

● XML code for EditText:<EditText

android:id="@+id/name_field"android:inputType =

"textPersonName"...

30

Page 31: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

31EditText for message

● android:inputType="textShortMessage"

● Single line of text● Tapping Emoticons key changes

keyboard to emoticons

31

Emoticons

Page 32: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

32EditText for single line

● Both work:○ android:inputType

="textLongMessage"○ android:inputType

="textPersonName"

● Single line of text● Tapping Done key advances focus to

next View

32

Done key

Page 33: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

33EditText for phone number entry

● android:inputType ="phone"

● Numeric keypad (numbers only)

● Tapping Done key advances focus to

next View

33

Done key

Page 34: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

34

● textCapCharacters: Set to all capital letters● textCapSentences: Start each sentence with a capital letter● textPassword: Conceal an entered password● number: Restrict text entry to numbers● textEmailAddress: Show keyboard with @ conveniently located● phone: Show a numeric phone keypad● datetime: Show a numeric keypad with a slash and colon for entering

the date and time

34

Common input types

Page 35: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

35

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Providing choices

35

Page 37: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

37CheckBox

● User can select any number of choices● Checking one box does not uncheck another● Users expect checkboxes in a vertical list● Commonly used with a Submit button● Every CheckBox is a View and can have

an onClick handler

37

Page 38: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

38RadioButton

● Put RadioButton elements in a RadioGroup in a vertical list (horizontally if labels are short)

● User can select only one of the choices● Checking one unchecks all others in group● Each RadioButton can have onClick

handler● Commonly used with a Submit button

for the RadioGroup

38

Page 39: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

39Toggle buttons and switches

● User can switch between on and off● Use android:onClick for click handler

Toggle buttons

Switches

39

Presenter
Presentation Notes
Page 40: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

40

4.3 Menus and pickers

40

Page 41: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

41Contents

● Overview

● App Bar with Options Menu

● Contextual menus

● Popup menus

● Dialogs

● Pickers

41

Page 42: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

42

1. App bar with options menu

2. Context menu

3. Contextual action bar

4. Popup menu

Types of Menus

42

Page 43: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

43Dialogs and pickers

43

1 2 3

1. Alert dialog

2. Date picker

3. Time picker

Page 44: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

44

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

App Bar with Options Menu

44

Page 45: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

45

What is the App Bar?

45

Bar at top of each screen—same for all devices (usually)

1. Nav icon to open navigation drawer

2. Title of current Activity

3. Icons for options menu items

4. Action overflow button forthe rest of the options menu

Page 46: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

46

● Appears in the right corner of the app bar (3)

● For navigating to other activities and editing app settings

What is the options menu?

46

● Action icons in the app bar for important items (1)

● Tap the three dots, the "action overflow button" to see the options menu (2)

Page 47: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

47

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Contextual Menus

47

Page 48: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

48What are contextual menus?

48

● Allows users to perform action on selected View

● Can be deployed on any View

● Most often used for items in RecyclerView, GridView, or other View collection

Page 49: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

49Types of contextual menus

49

● Floating context menu—long-press on a View ○ User can modify View or use it in some fashion○ User performs action on one View at a time

● Contextual action mode—temporary action bar in place of or underneath app bar○ Action items affect the selected View element(s)○ User can perform action on multiple View elements at once

Page 50: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

50

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Popup Menu

50

Page 51: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

51What is a popup menu?

51

● Vertical list of items anchored to a view

● Typically anchored to a visible icon

● Actions should not directly affect view content○ Options menu overflow icon that opens options menu

○ In email app, Reply All and Forward relate to email message but don’t affect or act on message

Page 52: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

52

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Dialogs

52

Page 54: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

54AlertDialog

54

AlertDialog can show:

1. Title (optional)

2. Content area

3. Action buttons

Presenter
Presentation Notes
Alerts are urgent interruptions, requiring acknowledgement, that inform the user about a situation as it occurs, or an action before it occurs (as in discarding a draft). You can provide buttons in an alert to make a decision. For example, an alert dialog might require the user to click Continue after reading it, or give the user a choice to agree with an action by clicking a positive button (such as OK or Accept), or to disagree by clicking a negative button (such as Cancel). Use the AlertDialog subclass of the Dialog class to show a standard dialog for an alert. The AlertDialog class allows you to build a variety of dialog designs. An alert dialog can have the following regions (refer to the diagram below): Title: A title is optional. Most alerts don’t need titles. If you can summarize a decision in a sentence or two by either asking a question (such as, “Discard draft?”) or making a statement related to the action buttons (such as, “Click OK to continue”), don’t bother with a title. Use a title if the situation is high-risk, such as the potential loss of connectivity, and the content area is occupied by a detailed message, a list, or custom layout. Content area: The content area can display a message, a list, or other custom layout. Action buttons: You should use no more than three action buttons in a dialog, and most have only two.
Page 55: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

55

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Pickers

55

Page 57: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

57Pickers use fragments

● Use DialogFragment to show a picker

● DialogFragment is a window that floats on top of Activity window

57

Page 58: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

58Introduction to fragments

● A Fragment is like a mini-Activity within an Activity○ Manages its own own lifecycle○ Receives its own input events

● Can be added or removed while parent Activity is running

● Multiple fragments can be combined in a single Activity

● Can be reused in more than one Activity

58

Page 59: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

59

4.4 User navigation

59

Page 60: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

60Contents

● Back navigation ● Hierarchical navigation

○ Ancestral navigation○ Descendant navigation○ Lateral navigation

60

Page 61: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

61

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Back Navigation

61

Page 62: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

62Back Navigation

62

● Provided by the device's Back button

● Controlled by the Android system back stack

Page 63: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

63

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Hierarchical Navigation

63

Page 64: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

64Hierarchical navigation patterns

64

● Parent screen—Screen that enables navigation down to child screens, such as home screen and main Activity

● Collection sibling—Screen enabling navigation to a collection of child screens, such as a list of headlines

● Section sibling—Screen with content, such as a story

Page 65: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

Android Developer Fundamentals V2

This work is licensed under a Creative Commons Attribution 4.0 International License.

Buttons and clickable images

Top Stories

Example of a screen hierarchy

65

1. Parent 2. Children: collection siblings3. Children: section siblings

● Use Activity for parent screen ● Use Activity or Fragment for

children screens

HeadlineHeadlineHeadlineHeadline

News App

Story Story Story

Tech NewsHeadlineHeadlineHeadlineHeadline

CookingHeadlineHeadlineHeadlineHeadline

1

2

3

Page 66: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

66Types of hierarchical navigation

66

● Descendant navigation○ Down from a parent screen to one of its children○ From a list of headlines—to a story summary—to a story

● Ancestral navigation○ Up from a child or sibling screen to its parent○ From a story summary back to the headlines

● Lateral navigation○ From one sibling to another sibling○ Swiping between tabbed views

Page 67: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

67

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Descendant Navigation

67

Page 68: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

Android Developer Fundamentals V2

This work is licensed under a Creative Commons Attribution 4.0 International License.

Buttons and clickable images

Descendant navigation

68

Descendant navigation

● Down from a parent screen to one of its children

● From the main screen to a list of headlines to a story

Top StoriesHeadlineHeadlineHeadlineHeadline

News App

Story Story Story

Tech NewsHeadlineHeadlineHeadlineHeadline

CookingHeadlineHeadlineHeadlineHeadline

Page 69: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

69

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Ancestral Navigation

69

Page 70: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

70Ancestral navigation (Up button)

70

● Enable user to go up from a sectionor child screen to the parent

Page 71: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

71

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Lateral Navigation

71

Page 72: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

Android Developer Fundamentals V2

This work is licensed under a Creative Commons Attribution 4.0 International License.

Buttons and clickable images

Tabs and swipes

72

Lateral navigation

● Between siblings

● From a list of stories to a list in a different tab

● From story to story under the same tab

Top StoriesHeadlineHeadlineHeadlineHeadline

News App

Story Story Story

Tech NewsHeadlineHeadlineHeadlineHeadline

CookingHeadlineHeadlineHeadlineHeadline

Page 73: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

73Best practices with tabs

73

● Lay out horizontally

● Run along top of screen

● Persistent across related screens

● Switching should not be treated as history

Page 74: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

74

4.5 RecyclerView

74

Page 75: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

75Contents

● RecyclerView Components

● Implementing a RecyclerView

75

Page 76: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

76What is a RecyclerView?

● RecyclerView is scrollable container for large data sets

● Efficient ○ Uses and reuses limited number of

View elements○ Updates changing data fast

76

Page 77: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

77How it works

77

Page 78: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

78

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

RecyclerView Components

78

Page 79: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

79

● Data

● RecyclerView scrolling list for list items—RecyclerView

● Layout for one item of data—XML file

● Layout manager handles the organization of UI components in a View—Recyclerview.LayoutManager

● Adapter connects data to the RecyclerView—RecyclerView.Adapter

● ViewHolder has view information for displaying one item—RecyclerView.ViewHolder

79

Overview

Page 80: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

80

80

How components fit together overview

Page 81: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

81

● Each ViewGroup has a layout manager

● Use to position View items inside a RecyclerView

● Reuses View items that are no longer visible to the user

● Built-in layout managers ○ LinearLayoutManager○ GridLayoutManager○ StaggeredGridLayoutManager

● Extend RecyclerView.LayoutManager

81

What is a layout manager?

Page 82: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

82Playstore

82

Page 83: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

83Instagram

83

Page 84: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

84

● Helps incompatible interfaces work together○ Example: Takes data from database Cursor and prepares strings

to put into a View● Intermediary between data and View● Manages creating, updating, adding, deleting View items as

underlying data changes

● RecyclerView.Adapter

84

What is an adapter?

Presenter
Presentation Notes
Page 85: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

85

● Used by the adapter to prepare one View with data for one list item

● Layout specified in an XML resource file● Can have clickable elements● Is placed by the layout manager

● RecyclerView.ViewHolder

85

What is a ViewHolder?

Page 86: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

86

Android Developer Fundamentals V2 Buttons and

clickable imagesThis work is licensed under a Creative Commons Attribution 4.0 International License.

Implementing RecyclerView

86

Page 87: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

87

1. Add RecyclerView dependency to build.gradle if needed2. Add RecyclerView to layout3. Create XML layout for item4. Extend RecyclerView.Adapter5. Extend RecyclerView.ViewHolder6. In Activity onCreate(), create RecyclerView with adapter

and layout manager

87

Steps Summary

Page 88: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

88

Thank YouAny Question ? ?

Page 89: Kode ISH1E3 – Algoritma dan Pemrogramanrahmatfauzi.com/wp-content/uploads/2020/02/W5-USER...8 Android Developer Fundamentals V2 Buttons and clickable images This work is licensed

89

Daftar Referensi

1)https://developer.android.com/courses/fundamentals-training/toc-v2