Microsoft PowerPoint - 08_Android_Spring11_Control2.pptx

Similar documents
主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new

Android Service

多媒體應用 13 新增專案並完成版面配置 <ExMusic01> <activity_main.xml> ImageView ID imgplay ImageView ID imgstop ImageView ID imgfront TextView ID txtsong TextView ID t

用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應

Chapter 9: Objects and Classes

Dynamic Layout in Android

The Embedded computing platform

Chapter 4

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

建模与图形思考

實作SQLiteOpenHelper類別

Android 编程基础 Android 开发教程 & 笔记 1

untitled

EJB-Programming-4-cn.doc

建立Android新專案

untitled

Android Fragment

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class

res/layout 目录下的 main.xml 源码 : <?xml version="1.0" encoding="utf 8"?> <TabHost android:layout_height="fill_parent" xml

單步除錯 (1/10) 打開 Android Studio, 點選 Start a new Android Studio project 建立專案 Application name 輸入 BMI 點下 Next 2 P a g e

RecyclerView and CardVew

Microsoft Word - 01.DOC

chp6.ppt

Microsoft PowerPoint - 07.Android 介面元件-TableLayout、Toast、AlertDialog

Java

建立Android新專案

Android 基礎教學

untitled

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

_banneradview.setuserkeywords("swimming"); _banneradview.setusercategories("1,3,4"); _banneradview.setusergender(jdbanneradview.gender_male); _bannera

第6讲

投影片 1

Microsoft Word - 第4章 3D相册.doc

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

INTRODUCTION TO COM.DOC

Database_001

Chapter 10

EJB-Programming-3.PDF

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

Microsoft Word - weather12 刷新按钮动画+搜索框+bug处理.docx

3.1 num = 3 ch = 'C' 2

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 號 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民

Microsoft Word - 第3章.doc

Microsoft PowerPoint - 02_Android_Spring11_Installation.pptx

Android + NFC

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

報 告 議 員, 本 局 對 臺 北 市 列 管 的 地 下 加 油 站, 大 部 分 都 已 取 締 完 畢 目 前 只 剩 下 1 處, 我 們 還 在 持 續 觀 察 其 是 否 有 復 業 的 跡 象 臺 北 市 的 地 下 加 油 站 只 剩 下 1 處 而 已? 王 科 長 三 中 :

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

建模与图形思考

《大话设计模式》第一章

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

概述


untitled

輕鬆學 Dreamweaver CS5 網頁設計..\Example\Ch0\ \.html..\example\ch0\ \mouse.txt..\example\ch0\ \ _Ok.html 學習重點 JavaScript 複製程式碼 mouse.txt Ctrl+C Ctrl+C 0-4

基于ECO的UML模型驱动的数据库应用开发1.doc

6-?????C???{???]?p

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

Microsoft Word - AEL CH05.doc

Microsoft Word - 小心翼翼的二十一點N.doc

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

1.5招募说明书(草案)

「西醫基層總額支付委員會《第28次委員會議紀錄

(Microsoft Word \256\325\260\310\267|\304\263\260O\277\375_\252k\250\356_.doc)

Microsoft Word - 桂电教[2008]8号.doc

教育心理学教学案例分析

nb.PDF

预览图 : (2) 在 SelectCity.java 中增加控件, 用于绑定 select_city 文件的 ListView, TextView,EditTest 等控件 代码和注释如下 :

PowerPoint 簡報

(Microsoft Word - \244g\246a\247B\244\275\253H\245\365\244\247\275\325\254d\254\343\250s doc)

untitled

ltu

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

Microsoft PowerPoint - ch6 [相容模式]

Microsoft Word - OPIGIMAC 譯本.doc

Swing-02.pdf

電機工程系認可證照清單 /7/1

【主持人】:给大家介绍一下,这次的培训是我们画刊部的第三次培训,当然今天特别有幸请来著吊的摄影家李少白老师给我们讲课


RxJava

麻 省 理 工 學 院 是 在 西 元 2013 年 12 月 3 日 推 出 MIT App Inventor 2 網 站, 提 供 免 費 的 雲 端 服 務, 使 用 者 可 以 透 過 瀏 覽 器 來 開 發 Android 裝 置 應 用 程 式, 該 網 站 的 網 址 為 : http

Microsoft Word - Chap04.doc

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

相 应 功 能 (5) 再 将 Boy 类 作 为 Girl 类 的 友 元 类, 在 Boy 类 的 某 成 员 函 数 VisitGirl(Girl & ) 中 访 问 Girl 类 的 私 有 成 员, 观 察 编 译 器 给 出 的 信 息 ( 6 ) 删 除 两 个 类 中 的 函 数 V

没 有 多 余 的 Contruol 或 Action 了 原 来 Domain 层 被 服 务 层 Service layer 遮 挡, 在 右 边 图 中, 则 Domain 层 直 接 暴 露 给 前 台 了, 没 有 被 遮 挡, 裸 露 了 这 样 一 步 到 位 实 现 领 域 模 型

Microsoft PowerPoint - plan08.ppt

今天 年春季号 总 92 期

*

( ) / / / / / / /

(Microsoft Word - 8\244T\244\362\277\337\272]\244W\265L\246W.doc)

Microsoft Word - 專家本色 doc


但, 你 应 该 听 过 我 们 走 在 大 路 上 这 首 歌, 或 许 还 知 道 革 命 人 永 远 是 年 轻 那 支 歌 ; 并 且, 几 乎 可 以 肯 定, 你 在 戴 红 领 巾 的 那 阵, 必 然 唱 过 牛 儿 还 在 山 坡 吃 草, 放 牛 的 却 不 知 道 哪 儿 去

2 临 终 助 念 答 问 序 临 终 关 怀, 由 佛 门 净 宗 古 来 祖 师 大 德 提 倡 助 念 往 生, 现 今 已 渐 为 社 会 大 众 所 重 视, 在 台 湾, 台 大 长 庚 等 各 大 医 院, 也 都 设 有 助 念 室 ; 大 陆 上 许 多 道 场, 也 有 专 为

校园之星

Microsoft Word - 澎湖田調報告-宏達組9804.doc

<4D F736F F F696E74202D FA8BEA861B8EAB7BDBEE3A658BB50C0B3A5CE28B773A6CBA5AB29>

Transcription:

作者 : 李昭賢作者 : 洪振偉編撰整理者 : 陳彥霖

學習目標 1. 透過 XML 產生控制項 2. 透過 Java 產生控制項 3. 新增事件 (Event) 處理

AnalogClock / DigitalClock 負責顯示時間 AnalogClock: 以傳統鐘錶指針方式顯示時與分 DigitalClock: 以數位數字方式顯示時 分與秒 類比小時鐘 (AnalogClock 類別 ) 數位小時鐘 (DigitalClock 類別 )

AnalogClock / DigitalClock AnalogClock 與 DigitalClock 僅負責顯示時間, 若在程式碼內需要取得時間, 則直接取得系統時間, 並透過 Calendar 物件轉換出時間細節資訊 // 取得系統時間 time long time = System.currentTimeMillis(); // 建立日曆 mcalendar Calendar mcalendar = Calendar.getInstance(); mcalendar.settimeinmillis(time); // 讀到當時的時 / 分 int mhour = mcalendar.get(calendar.hour); int mminutes = mcalendar.get(calendar.minute);

Chronometer 用來計時之用 MM:SS H:MM:SS 透過 start() 可自動開始計時, 同時顯示當下的計時數值 透過 stop() 可停止計時

Chronometer 配合 Button 控制開始或停止計時 // 按下 Button01 按鈕時,Button01 被設計成交替切換按鈕, 可以開始計時或停止計時 button = (Button)findViewById(R.id.Button01); button.setonclicklistener(new View.OnClickListener() { public void onclick(view v) { if (button.gettext().equals("start")) { chronometer.start(); button.settext("stop"); else { chronometer.stop(); button.settext("start"); );

DatePicker/TimePicker DatePicker 可用來選擇日期 ( 年 月 日 ) TimePicker 可用來選擇時間 ( 時 分 )

DatePicker/TimePicker 可透過 getxxx() 取得相關資訊 final DatePicker datepicker = (DatePicker) findviewbyid(r.id.datepicker01); int year = datepicker.getyear(); int month = datepicker.getmonth() + 1; int day = datepicker.getdayofmonth(); final TimePicker timepicker = (TimePicker) findviewbyid(r.id.timepicker01); int hour = timepicker.getcurrenthour(); int minute = timepicker.getcurrentminute();

RatingBar / SeekBar 用圖形來設定數值大小的控制項 RatingBar SeekBar

RatingBar / SeekBar 可分別接受 RatingBar 與 SeekBar 數值改變的事件 RatingBar ratingbar01 = (RatingBar) findviewbyid(r.id.ratingbar01); ratingbar01.setonratingbarchangelistener(new OnRatingBarChangeListener(){ public void onratingchanged(ratingbar ratingbar, float rating, boolean fromuser) { textview01.settext(float.tostring(ratingbar01.getrating())); ); SeekBar mseekbar01 = (SeekBar) findviewbyid(r.id.seekbar01); mseekbar01.setonseekbarchangelistener(new OnSeekBarChangeListener() { public void onprogresschanged(seekbar mseekbar, int progress, boolean fromtouch) { mtextview02.settext(" 用 Seek Bar 表示 :" + mseekbar01.getprogress()); );

ProgressBar ProgressBar 採用圖形表示正在處理中 長條狀圖形 不斷繞圈圈的圓形圖 是否可視 visible invisible gone 說明可視的, 設定初值不可視的, 但顯示組件仍然存在顯示組件已不存在

ProgressBar ProgrssBar 內容常透過額外的 Thread 更新 // 建立一個 Thread 來 Run Thread thread = new Thread() { @Override public void run() { try { for (int i = 0; i < progressbar.getmax() / 10; i++) { for (int j = 0; j < progressbar.getmax(); j++) { Thread.sleep(20); handler.post(callback1); handler.post(callback2); handler.post(callback3); catch (InterruptedException e) { e.printstacktrace(); ; thread.start();

ProgressBar // 設定 Handler 類別 final Handler handler = new Handler(); // 次要進度顯示處理程式 - callback1 final Runnable callback1 = new Runnable() { public void run() { progressbar.incrementsecondaryprogressby(1); setsecondaryprogress(100 * progressbar.getsecondaryprogress()); ; // 主要進度顯示處理程式 - callback2 final Runnable callback2 = new Runnable() { public void run() { progressbar.incrementprogressby(10); setprogress(100 * progressbar.getprogress()); progressbar.incrementsecondaryprogressby(-100); setsecondaryprogress(100 * progressbar.getsecondaryprogress()); ;

ProgressBar // 顯示圖形處理程式 - callback3 final Runnable callback3 = new Runnable() { public void run() { TextView textview = (TextView)findViewById(R.id.TextView01); textview.setvisibility(view.gone); progressbar.setvisibility(view.gone); ImageView imageview = (ImageView)findViewById(R.id.ImageView01); imageview.setimageresource(r.drawable.sakura01); imageview.setvisibility(view.visible); ;

警示互動對話盒 Android 提供五種類型的對話盒, 用來提供警示, 或與人互動之用 PopupWindow Dialog AlertDialog ProgressDialog Toast

PopupWindow 可設定的屬性較多, 如 : 視窗的長和寬 視窗出現的座標 等 PopupWindow popupwindow = new PopupWindow(PopupActivity.this); popupwindow.setcontentview(button); popupwindow.setfocusable(true); popupwindow.setwidth(200); popupwindow.setheight(100); popupwindow.showatlocation(view, Gravity.CENTER, 0, 0); // 按下對話視窗關閉 PopupWindow 視窗 button.setonclicklistener(new OnClickListener() { public void onclick(view v) { popupwindow.dismiss(); );

Dialog 最基本的對話盒類型, 可設定標題 訊息與按鈕, 按下按鈕就會關閉對話盒 Dialog dialog = new Dialog(PopupActivity.this); dialog.settitle(" 這裡可以用來顯示 Dialog 信息!"); dialog.setcontentview(button); dialog.show(); // 按下對話視窗上的按鈕來關閉 Dialog 視窗 button.setonclicklistener(new OnClickListener() { public void onclick(view v) { dialog.dismiss(); );

AlertDialog with buttons 專門用來警示的對話盒, 預設沒有按鈕可關閉視窗, 除非利用 AlertDialog.Builder 類別產生對話盒, 可透過 setpositivebutton() 或 setnegativebutton() 加上按鈕 AlertDialog.Builder builder = new AlertDialog.Builder(PopupActivity.this); builder.settitle("alertdialog"); builder.setmessage(" 這裡可以用來顯示 Alert 信息, 要按 [ 回上頁 ] 鍵才會關閉 "); builder.setpositivebutton( OK, new DialogInterface.OnClickListener(){ public void onclick(dialoginterface dialoginterface, int i) { dialoginterface.dismiss(); ); builder.show();

AlertDialog with buttons PositiveButton 配置於對話框左邊, 用於提示使用者有關 正確 或者 是 的選項 NeutralButton 配置於對話框中間 NegativeButton 配置於對話框右邊, 用於提示使用者有關 錯誤 否定 或者 否 的選項 Positive/Neutral/Negative 並不絕對用於字面意義, 可視為三個 一般 但是位置固定的按鈕

AlertDialog with buttons

ProgressDialog 除了產生 ProgressDialog 外, 類似 ProgressBar 必須產生額外的 thread 負責改變進度資料, 結束後連帶關閉對話盒 ProgressDialog progressdialog = ProgressDialog.show(PopupActivity.this, " 處理中...", " 請等一會, 處理完畢會自動結束...");

Toast 產生的對話盒, 會出現一段時間後自動消失 maketext() 可設定 " 產生的應用程式 " " 文字訊息 " " 顯示時間長短 " show() 顯示於視窗上 Toast.makeText(PopupActivity.this, 可以用來顯示 Toast 信息, 短時間後自動關閉 ", Toast.LENGTH_SHORT).show();

GridView 採用網格選單方式來展示 照片 同時也可以設定網 格選單選項時的監聽功能 程式 Google Android 2.X應用程式開發實戰 碁峰出版

GridView 類似 AutoComplteTextView 需要搭配 StringArray, GridView 必須搭配產生繼承 BaseAdapter 的物件用來儲存圖片 public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.grid_activity); GridView gridview = (GridView)findViewById(R.id.GridView01); gridview.setadapter(new ImageAdapter(this)); gridview.setonitemclicklistener(new OnItemClickListener() { public void onitemclick(adapterview<?> parent, View v, int position, long id) { Toast.makeText(GridActivity.this, "" + position, Toast.LENGTH_SHORT).show(); );

GridView // 建構 ImageAdapter 類別程式 public class ImageAdapter extends BaseAdapter { private Context mcontext; public ImageAdapter(Context c) { mcontext = c; public int getcount() { return mthumbids.length; public Object getitem(int position) { return null; public long getitemid(int position) { return 0;

GridView // 建立一個 imageview 來安置每一個圖像, 並提供給 Adapter public View getview(int position, View convertview, ViewGroup parent) { ImageView imageview; if (convertview == null) { // if it's not recycled, initialize some attributes imageview = new ImageView(mContext); imageview.setlayoutparams(new GridView.LayoutParams(85, 85)); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setpadding(8, 8, 8, 8); else { imageview = (ImageView) convertview; imageview.setimageresource(mthumbids[position]); return imageview;

GridView // 設定圖像檔案陣列 private Integer[] mthumbids = { R.drawable.sakura01s, R.drawable.sakura02s, R.drawable.sakura03s, R.drawable.sakura04s, R.drawable.sakura05s, R.drawable.sakura06s, R.drawable.sakura07s, R.drawable.sakura08s, R.drawable.sakura09s, R.drawable.sakura10s, R.drawable.sakura11s, R.drawable.sakura12s, R.drawable.sakura02s, R.drawable.sakura04s, R.drawable.sakura06s, R.drawable.sakura08s, R.drawable.sakura10s, R.drawable.sakura12s, R.drawable.icon, R.drawable.icon, R.drawable.icon ; public View getview1(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub return null;

Gallery 依序排列成一橫列展示圖片 用法類似GridView 必須繼 承BaseAdapter產生負責儲存 圖片的物件 Google Android 2.X應用程式開發實戰 碁峰出版

VideoView 播放影像時利用 VideoView 的方法可以設定影像檔案所在路徑和放在媒體控制器 (Media Controller) 容器上, 可以播放 (Play) 暫停 (Pause) 向前 (Fore Forward) 和向後 (Back Forward)

VideoView Android 內建僅支援部分影像檔案, 如 :H.263(*.3gp or *.mp4) H.264 AVC (*.3gp or *.mp4) MPEG-4 SP(*.3gp) VP8(*.webm) 等 VideoView videoview = (VideoView)findViewById(R.id.VideoView01); videoview.setvideopath("/data/sample.3gp"); videoview.setmediacontroller(new MediaController(this));

總結 了解各個控制項使用的方式與功能 時間控制項 AnalogClock DigitalClock Chronometer DatePicker TimePicker 進度控制項 RatingBar SeekBar ProgressBar 對話盒視窗控制項 PopupWindow Dialog AlertDialog ProgressDialog Toast 其他 GridView Gallery VideoView