tku行動app開發管理實務 - listview & custom adapter

36
行動APP開發管理實務 實作簡易網路資料瀏覽App ListView與資料的串接 – ListView & Custom Adapter 尹君耀 Xavier Yin

Upload: xavier-yin

Post on 22-Jan-2018

720 views

Category:

Education


2 download

TRANSCRIPT

Page 1: TKU行動APP開發管理實務 - ListView & Custom Adapter

行動APP開發管理實務實作簡易網路資料瀏覽App

ListView與資料的串接 – ListView & Custom Adapter

尹君耀 Xavier Yin

Page 2: TKU行動APP開發管理實務 - ListView & Custom Adapter

課程大綱

上週課程實作步驟

輔助工具

基礎控制項 & ViewGroup

ListView

實作步驟

Page 3: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

開新專案並選擇 Navigation Drawer Activity Empty Activity

Page 4: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

從Project Structure匯入相關Libs – Volley和Gson

Page 5: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

新增欲實作的Layout – 新增activity_raw_data.xml

Page 6: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

修改MainActivity.java– 初始Volley的工作佇列

– 產生相對應的UI元件

– 註冊按鈕相關事件

– 呼叫Volley Request元件

Page 7: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

初始Volley的工作佇列– 新增initApiRequestQueue()

Page 8: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

產生相對應的UI元件– 新增prepareUI ()

Page 9: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

註冊按鈕相關事件– 實作button OnclickListener監聽方法

– 新增prepareEvents ()

Page 10: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

呼叫Volley Request元件– 新增名為beans的package,並新增一個MyDataResult物件作為Gson剖析後的Bean data。

– 產生StringRequest物件,並實作Listener和ErrorListener方法

– 新增invokeStringRequest ()

Page 11: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

在Manifest加上Internet權限

執行程式並觀察結果

Page 13: TKU行動APP開發管理實務 - ListView & Custom Adapter

輔助工具

Json Parser Online

Page 14: TKU行動APP開發管理實務 - ListView & Custom Adapter

基本元件

Activity

Service

BroadcastReceiver

ContentProvider

Page 15: TKU行動APP開發管理實務 - ListView & Custom Adapter

控制項

View class– This class represents the basic

building block for user interfacecomponents.

ViewGroup class– The ViewGroup subclass is the base

class for layouts, which are invisiblecontainers that hold other Views (orother ViewGroups) and define theirlayout properties.

Page 16: TKU行動APP開發管理實務 - ListView & Custom Adapter

控制項

View class– This class represents the basic

building block for user interfacecomponents.

ViewGroup class– The ViewGroup subclass is the base

class for layouts, which are invisiblecontainers that hold other Views (orother ViewGroups) and define theirlayout properties.

Page 17: TKU行動APP開發管理實務 - ListView & Custom Adapter

Button

Button – Represents a push-button widget. Push-buttons can be pressed, or

clicked, by the user to perform an action.

– A button consists of text or an icon (or both text and an icon) thatcommunicates what action occurs when the user touches it.

Page 18: TKU行動APP開發管理實務 - ListView & Custom Adapter

TextView and EditText

TextView– Displays text to the user and

optionally allows them to editit.

EditText– EditText is a thin veneer over

TextView that configures itselfto be editable.

Page 19: TKU行動APP開發管理實務 - ListView & Custom Adapter

LinearLayout

android:orientation -setOrientation(int)– Should the layout be a column

or a row? Use "horizontal" for a row, "vertical" for a column.

android:gravity -setGravity(int)– Specifies how an object should

position its content, on both the X and Y axes, within its own bounds.

Page 20: TKU行動APP開發管理實務 - ListView & Custom Adapter

LinearLayout

Practice

Horizontal Vertical & Horizontal

Page 21: TKU行動APP開發管理實務 - ListView & Custom Adapter

FrameLayout

Practice

Page 22: TKU行動APP開發管理實務 - ListView & Custom Adapter

RelativeLayout

android:layout_above, android:layout_below– Positions the bottom edge of this view above or below the given anchor view ID.

android:layout_alignParentBottom, android:layout_alignParentLeft, android:layout_alignParentRight, android:layout_alignParentTop– If true, makes the edge of this view match the edge you assign of the parent.

android:layout_toLeftOf, android:layout_toRightOf– Positions the right edge of this view to the left or right of the given anchor view

ID.

android:layout_centerInParent– If true, centers this child horizontally and vertically within its parent.

Page 23: TKU行動APP開發管理實務 - ListView & Custom Adapter

RelativeLayout

Practice

Page 24: TKU行動APP開發管理實務 - ListView & Custom Adapter

Event Listeners

Event Listeners– An event listener is an interface in the View class that contains a single

callback method. These methods will be called by the Androidframework when the View to which the listener has been registered istriggered by user interaction with the item in the UI.

– Included in the event listener interfaces are the following callbackmethods:

onClick()

onTouch()

onLongClick()

onFocusChange()

onKey()

Page 25: TKU行動APP開發管理實務 - ListView & Custom Adapter

ListView

ListView is a view group that displays a list of scrollable items.

The list items are automatically inserted to the list using anAdapter that pulls content from a source such as an array ordatabase query and converts each item result into a viewthat's placed into the list.

Page 26: TKU行動APP開發管理實務 - ListView & Custom Adapter

ListView

Page 27: TKU行動APP開發管理實務 - ListView & Custom Adapter

ListView

Page 28: TKU行動APP開發管理實務 - ListView & Custom Adapter

BaseAdapter

onCreate()– How many items are in the data set represented by this Adapter.

getItem(int position)– Get the data item associated with the specified position in the data set.

getItemId(int position)– Get the row id associated with the specified position in the list.

getView(int position, View convertView, ViewGroup parent)– Get a View that displays the data at the specified position in the data set.

setTag(Object tag)– Sets the tag associated with this view.

Page 29: TKU行動APP開發管理實務 - ListView & Custom Adapter

Intent

An intent is an abstract description of an operation to beperformed. It can be used with startActivity to launch an Activity,broadcastIntent to send it to any interested BroadcastReceivercomponents, and startService(Intent) or bindService(Intent,ServiceConnection, int) to communicate with a backgroundService.

An Intent provides a facility for performing late runtime bindingbetween the code in different applications. Its most significant useis in the launching of activities, where it can be thought of as theglue between activities. It is basically a passive data structureholding an abstract description of an action to be performed.

Page 30: TKU行動APP開發管理實務 - ListView & Custom Adapter

Intent

putExtra(String name, int value)

putExtra(String name, Serializable value)

putExtra(String name, Bundle value)– Add extended data to the intent.

Page 31: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

匯入Picasso Lib

Page 32: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

新增欲實作的Layout – 新增activity_landscape.xml

Page 33: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

新增欲實作的Layout – 新增list_item_landscape.xml

Page 34: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

新增欲實作的Layout – 新增activity_location.xml

Page 35: TKU行動APP開發管理實務 - ListView & Custom Adapter

實作步驟

新增欲實作的Java程式– 新增LandscapeListAdapter.java

– 新增LandscapeActivity.java

– 新增LocationActivity.java

Manifest加上新增的Activity檔案

Page 36: TKU行動APP開發管理實務 - ListView & Custom Adapter

Sample Code and Slides

Slides (Xavier Yin 尹君耀)– https://www.slideshare.net/secret/qwwnf2FPdyjYO

Sample Code (TKUEasySampleCode)– https://github.com/xavier0507/TKUEasySampleCode.git