TKU行動APP開發管理實務 - ListView & Custom Adapter
-
Upload
xavier-yin -
Category
Education
-
view
720 -
download
2
Transcript of TKU行動APP開發管理實務 - ListView & Custom Adapter
行動APP開發管理實務實作簡易網路資料瀏覽App
ListView與資料的串接 – ListView & Custom Adapter
尹君耀 Xavier Yin
課程大綱
上週課程實作步驟
輔助工具
基礎控制項 & ViewGroup
ListView
實作步驟
實作步驟
開新專案並選擇 Navigation Drawer Activity Empty Activity
實作步驟
從Project Structure匯入相關Libs – Volley和Gson
實作步驟
新增欲實作的Layout – 新增activity_raw_data.xml
實作步驟
修改MainActivity.java– 初始Volley的工作佇列
– 產生相對應的UI元件
– 註冊按鈕相關事件
– 呼叫Volley Request元件
實作步驟
初始Volley的工作佇列– 新增initApiRequestQueue()
實作步驟
產生相對應的UI元件– 新增prepareUI ()
實作步驟
註冊按鈕相關事件– 實作button OnclickListener監聽方法
– 新增prepareEvents ()
實作步驟
呼叫Volley Request元件– 新增名為beans的package,並新增一個MyDataResult物件作為Gson剖析後的Bean data。
– 產生StringRequest物件,並實作Listener和ErrorListener方法
– 新增invokeStringRequest ()
實作步驟
在Manifest加上Internet權限
執行程式並觀察結果
基本元件
Activity
Service
BroadcastReceiver
ContentProvider
控制項
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.
控制項
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.
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.
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.
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.
LinearLayout
Practice
Horizontal Vertical & Horizontal
FrameLayout
Practice
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.
RelativeLayout
Practice
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()
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.
ListView
ListView
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.
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.
Intent
putExtra(String name, int value)
putExtra(String name, Serializable value)
putExtra(String name, Bundle value)– Add extended data to the intent.
實作步驟
匯入Picasso Lib
實作步驟
新增欲實作的Layout – 新增activity_landscape.xml
實作步驟
新增欲實作的Layout – 新增list_item_landscape.xml
實作步驟
新增欲實作的Layout – 新增activity_location.xml
實作步驟
新增欲實作的Java程式– 新增LandscapeListAdapter.java
– 新增LandscapeActivity.java
– 新增LocationActivity.java
Manifest加上新增的Activity檔案
Sample Code and Slides
Slides (Xavier Yin 尹君耀)– https://www.slideshare.net/secret/qwwnf2FPdyjYO
Sample Code (TKUEasySampleCode)– https://github.com/xavier0507/TKUEasySampleCode.git