18
@scruffyfox esson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2 Android Lesson 2 by Callum Taylor

Android Course - Lesson2

Embed Size (px)

DESCRIPTION

Lesson 2 of the Android Course by Callum Taylor Slide notes here: https://github.com/scruffyfox/AndroidCourse/blob/Lesson-2/pdf/Lesson2-notes.pdf

Citation preview

Page 1: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

AndroidLesson 2 by Callum Taylor

Page 2: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

Introduction

• All code and presentation slides can be found over at https://github.com/scruffyfox/AndroidCourse

• Twitter/app.net/github: @scruffyfox

• http://(blog.)callumtaylor.net

Page 3: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

Introduction

https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

Page 4: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

What we’re going to make

Page 5: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

What we’re going to make

• ListView

• ArrayAdapter/BaseAdapter

• findViewById

• View Holder paradigm

Page 6: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

IDE Tips

+

Page 7: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

IDE Tips

+

Page 8: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

IDE Tips

+

Page 9: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

IDE Tips

+

Page 10: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How R.java works

R.layout.list_itemR.id.name

R.drawable.ic_launcher

Page 11: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How R.java works

R.string.hello_world

Page 12: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How Adapters work

• getCount()• getItem(int position)• getItemId(int position)• getView(int position, View

convertView, ViewGroup parent)

Page 13: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How Adapters work

• getCount()

Exactly what it says – returns the number of items in the current data set

Page 14: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How Adapters work

• getItem(int position)

Returns the item from the data set at the specific position

Page 15: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How Adapters work

• getItemId(int position)

Returns the item’s id at the position. Can just return 0, but return a reliable int ID/representation of the item to increase performance of the list view

Page 16: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How Adapters work

• getView(int position, View convertView, ViewGroup parent)

Returns the view in the list. This is where we do all of our data inflating into the screen which the user sees.

Position is the position of the item in the datasetConvertView is the view that will be shownParent is the parent view of the view being shown (usually the list view)

Page 17: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How List Views work

Page 18: Android Course - Lesson2

@scruffyfoxLesson 2 – https://github.com/scruffyfox/AndroidCourse/tree/Lesson-2

How List Views work

• getView(int position, View convertView, ViewGroup parent)