Microsoft PowerPoint - 05.Android 介面元件-RelativeLayout、Button、TextVeiw、EditText

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

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

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

PowerPoint 簡報

Android Fragment

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

Android Service

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

Microsoft Word - 02.目錄.doc

Dynamic Layout in Android

人民邮电

RecyclerView and CardVew

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

Android 开发教程

Microsoft Word - 第3章.doc

建立Android新專案

Microsoft PowerPoint - 12 jQuery Mobile 事件處理方式

Android Android Android SDK iv

小应用 Magic8

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

Microsoft PowerPoint - 09.Android 程式設計-SQLite

Microsoft PowerPoint - VB14.ppt

第一章 Android 简介与开发环境搭建

untitled

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

Microsoft Word - Android App开发从入门到精通.doc

<4D F736F F D205BCAE9B0FCCDF85DC8FDC9FAC8FDCAC0CAAEC0EFCCD2BBA82E646F6378>

0511-Android程式之GPS應用_專題週記4

0 0 = 1 0 = 0 1 = = 1 1 = 0 0 = 1

内文-2.indd

投影片 1

Android 开发教程

图 6-1 主界面 MainActivity 界面对应的布局文件 (activity_main.xml) 如下所示 : <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="

<4D F736F F D20342D312D302DB4FAC5E7C344A7DEAFE0B357BD64A4CEA4C0C3FEBD64A8D2C344A5D8>

雲端 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

任务实施 (1) 创建项目 图 3-1 欢迎界面 首先创建一个工程, 将其命名为 BoXueGu, 指定包名为 com.boxuegu (2) 导入界面图片将欢迎界面所需要的背景图片 launch_bg.png 导入到 drawable 文件夹中, 项目的 icon 图标 app_icon.png

untitled

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

建立Android新專案

单击以编辑母片 Content 标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 2

untitled

封面-12

untitled

2 WF 1 T I P WF WF WF WF WF WF WF WF 2.1 WF WF WF WF WF WF

書面

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

Android + NFC

Microsoft Word - Android App 手機應用程式設計課程-0429.docx

untitled

PowerPoint 簡報

<4D F736F F D20AC4FBDBDA4FBB67DA96CAABA2DA743A67EAFC5AAA95FA7B9BD5A5F2E646F63>

ex

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

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

Microsoft Word - Mail2000_SecurityPatch_

团 学 要 闻 我 校 召 开 共 青 团 五 届 九 次 全 委 ( 扩 大 ) 会 议 3 月 17 日, 我 校 共 青 团 五 届 九 次 全 委 ( 扩 大 ) 会 议 在 行 政 办 公 楼 五 楼 会 议 室 举 行, 校 团 委 委 员 各 院 ( 系 ) 团 委 书 记 校 学 生

untitled

VB程序设计教程

云 浮 市 总 工 会 学 习 贯 彻 市 委 五 届 九 次 全 会 精 神 全 省 工 会 第 二 季 度 暨 上 半 年 劳 资 纠 纷 研 判 会 召 开 河 源 市 总 工 会 召 开 劳 资 纠 纷 研 判 会 议 湛 江 市 总 工 会 召 开 上 半 年 劳 资 纠 纷 研 判 会

1. 2. Flex Adobe 3.

龚 翔 艺 江 西 省 吉 安 市 教 育 局 就 业 办 江 西 省 吉 安 市 韶 山 西 路 3 号 黄 羽 茜 艺 江 西 省 赣 州 市 教 育 局 就 业 办 江

汉 语 言 文 学 高 盼 盼 福 建 师 范 大 学 文 学 院 党 委 汉 语 言 文 学 张 森 远 河 南 师 范 大 学 研 招 办 汉 语 言 文 学 刘 沿

ShareText

可 Web 编程的NativeUI 设计与实现

( )... 5 ( ) ( )

The golden pins of the PCI card can be oxidized after months or years

Microsoft PowerPoint - 04 界面编程.ppt [兼容模式]

Microsoft Word - 01.DOC

建模与图形思考

現 在 和 他 熟 嗎? 我 當 了 衛 生 局 局 長 2 年 半 之 間, 大 概 臺 北 市 各 醫 院 的 院 長 都 認 得 了 我 的 記 者 會 結 束 後, 不 知 道 你 有 沒 有 接 到 什 麼 電 話? 沒 有 我 為 什 麼 要 這 麼 問 兩 位? 因 為 林 院 長 在

<4D F736F F D20CEEFC1AACDF8BCBCCAF5CAB5D1E9D6B8B5BCCAE E646F63>

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

Chapter 1: Introduction

投影片 1

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

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

Microsoft Word - 1-3陳詠琳-近代..


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

ActiveX Control

06 01 action JavaScript action jquery jquery AJAX CSS jquery CSS jquery HTML CSS jquery.css() getter setter.css('backgroundcolor') jquery CSS b

css-03.pdf

The Embedded computing platform

Microsoft Word - 各組上榜者讀書準備方法.doc

Microsoft Word - GUI design.doc

大陸教育部等6個部門公佈「現代職業教育體系建設規劃 ( 年)」規劃到2015年初步形成現代職業教育體系框架,到2020年基本建成「中國」特色現代職業教育體系

资 讯 速 递 台 基 于 大 数 据 的 学 校 督 导 评 估 系 统 建 设 上 海 市 闵 行 区 人 民 政 府 教 育 督 导 室 ( 摘 要 ) 闵 行 教 育 在 深 化 教 育 改 革 探 索 管 办 评 分 离 的 背 景 下, 把 教 育 督 导 评 估 系 统 建 设 作 为

浙江师范大学2014年度毕业生就业质量报告

目 录 监 管 资 讯 2016 年 全 国 保 险 监 管 工 作 会 议 召 开...3 协 会 动 态 赤 峰 保 险 行 业 协 会 召 开 数 据 统 计 和 信 息 宣 传 总 结 表 彰 会 议...5 赤 峰 市 保 险 行 业 协 会 秘 书 处 召 开 2015 年 度 述 职

同 时, 采 取 提 供 新 闻 线 索 和 素 材 安 排 专 访 等 方 式 主 动 为 新 闻 媒 体 服 务, 为 采 访 报 道 活 动 创 造 便 利 条 件 建 设 网 络 信 息 发 布 平 台 2013 年 9 月 开 通 中 央 纪 委 监 察 部 网 站,2015 年 1 月

公務員服務法第13條相關解釋彙整表

B1

時間軸上的竹蓮記憶 學務主任 黃雅彙 我不是竹蓮國小的畢業校友 但對於身為新竹人的我來 說 仔細回想起來 似乎和竹蓮有著一種特別的緣分 對竹蓮國小最初的印象是在小學的時候 猶記得年幼的 我經過一段時日的啦啦隊舞蹈訓練後 老師便帶著我們從學 校步行到竹蓮國小來參加比賽 一踏入竹蓮校門 映入眼簾 的是黑

B1

Microsoft Word - 临政办发6.doc

1.5招募说明书(草案)

人 間 菩 提 Part 1 人 間 菩 提 Part 2 清 涼 菩 提 正 覺 修 行 清 心 發 願 自 重 ----

Cover-3.indd, page Normalize

FP.pdf


Transcription:

計劃名稱 : 104 年度教育部資通訊軟體創新人才推升推廣計畫跨校資源中心 : 雲端運算 ( 國立中山大學 ) 課程名稱 : 網路及平台服務 Part1- 課程教材 教材名稱 :Android 介面元件 -RelativeLayout Button TextVeiw EditText 國立高雄大學資訊工程學系張保榮教授

大綱 RelativeLayout 版面配置 Button 版面配置 TextView 版面配置 EditText 版面配置

RelativelLayout 版面配置 AndroidHello 專案的 [res/layout.xml] activity_main.xml

RelativelLayout 版面配置 ( 續 ) RelativeLayout 代表著配置的 ( 父 ) 容器, 在 RelativeLayout 版面配置中可以加入多個 ( 子 ) 元件的配置 ( 如 : 多個 Button TextView 等等 ) 而所有的( 子 ) 元件的位置都是相對於 ( 父 ) 容器或其兄弟元件來決定 RelativeLayout 語法如下 : <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android>.. 內容.. </RelativeLayout> 父容器 ( 即手機螢幕 ) 子元件

RelativelLayout 版面配置 ( 續 ) RelativeLayout 的版面配置設定為 true 或 false 的屬性, 如下所式 : 屬性名稱 android:layout_centerhorizontal android:layout_centervertical android:layout_centerinparent android:layout_alignparentbotton android:layout_alignparentleft android:layout_alignparentright android:layout_alignparenttop 定義子元件對其父容器橫向中間位置子元件對其父容器縱向中間位置子元件對其父容器中央位置子元件和父容器底部對齊子元件和父容器左側對齊子元件和父容器右側對齊子元件和父容器上緣對齊

RelativelLayout 版面配置 ( 續 ) 除了上述的基本配置設定外, 還有其他設定, 如下圖內容 : Layout_width Layout_height 代表物件的邊長與高度的設定 ( 之後將會說明內容語用法 ) 語法 padding 代表內邊距, 而 margin 代表著外邊距 定義上,padding 指的是子元件的內容與父容器內緣的距離 (padding 與 margin 的比較, 這部份會在下一章節 LinearLayout 再詳細說明 )

RelativelLayout 版面配置 ( 續 ) 元件的 id 設定與屬性配置 屬性名稱 android:id android:layout_ width android:layout_ height android:text 定義 辨識元件的 id, 並自動在 R.java 中建立索引, 再透過此 id 辨識這此元件 設定元件的文字寬度, 單位 :dp 另有 fill_parent match_parent wrap_content, 三種參數用法 設定元件的文字高度, 單位 :dp 另有 fill_parent match_parent wrap_content, 三種參數用法 設定元件顯示的文字名稱 fill_parent match_parent: 填滿整個外框 wrap_content: 依照文字的高度來自動調整高度

RelativelLayout 版面配置 ( 續 ) 元件的四周邊界 屬性名稱 定義 android:layout_marginleft( 單位 dp) 設定元件左側的邊界 android:layout_marginright( 單位 dp) 設定元件右側的邊界 android:layout_margintop( 單位 dp) 設定元件上方的邊界 android:layout_marginbottom( 單位 dp) 設定元件下方的邊界 用法 android:layout_marginleft= 100dp margin 代表著元件到外邊的外邊距

TextView 元件應用 圖形設計介面功能

TextView 元件應用 ( 續 ) TextView 語法用法有兩種 : <TextView>.( 內容 ). </TextView> <TextView>.( 內容 ). /> Ex: <TextView> android:id= @+id/( 元件名稱 ) android: 元件屬性 ( 名稱 )= 屬性值 / 內容 /> 例如 : android:text= Hello World 元件屬性 ( 名稱 ) text 屬性值 / 內容 Hello World

TextView 元件應用 ( 續 )

TextView 元件應用 ( 續 ) TextView 常用的屬性設定 屬性名稱對應的程式碼 (XML) 意義 height android:layout_height 設定元件的文字高度, 單位 :dp 另有 fill_parent match_parent wrap_content, 三種參數用法 width android:layout_width 設定元件的文字寬度, 單位 :dp 另有 fill_parent match_parent wrap_content, 三種參數用法 text android:text 設定欲顯示的文字內容 id android:id 設定元件的名稱 text color android:textcolor 設定元件的文字顏色, 單位 :#RGB 格式 ( 十六進位 制 ) 表示 如 :#FF0000, 代表紅色 text size android:textsize 設定文字的大小, 單位 :sp

TextView 元件應用 ( 續 ) 新增一個 TextView 設定 TextView 屬性 :id textcolor textsize text 等內容

TextView 元件應用 ( 續 ) 修改 [valuse] strings.xml 文件內容 新增一筆 xml 語法, 如下所示 :

TextView 元件應用 ( 續 ) TextView 的衍伸元件 :LargeText MediumText SamllText XML 語法如下 : LargeText:TextAppearance=?android:attr/terxtAppearance Large MediumText:TextAppearance=?android:attr/terxtAppearan cemedium SamllText:TextAppearance=?android:attr/terxtAppearance Small 分別為顯示大 中 小三種字體的用法

EditText 元件應用 設定 LargeText MediumText SamllText 的屬性 :id text textcolor, 如下圖所示 : 設定元件內容 字體顏色與大小

EditText 元件應用 ( 續 ) EditText 語法用法 : <EditText>.( 內容 ). /> Ex: <EditText> android:id= @+id/( 元件名稱 ) android: 元件屬性 ( 名稱 )= 屬性值 / 內容 /> 例如 : android:inputtype= text 元件屬性 ( 名稱 ) inputtype 屬性值 / 內容 text, 目的是讓使用者自行輸入字串 <requestfocus></ requestfocus >, 加入此行在 EditText 語法的內容位置, 功能在於程式執行時, 輸入線直接移至 ( 固定 )EditText 元件上

EditText 元件應用 ( 續 ) EditText 元件常用的屬性 : 屬性名稱對應的程式碼 (XML) 意義 lines android:line 設定最多可以顯示的列數 ems android:ems 設定每一烈的字元數, 此用法必須搭配屬 性 :width 的設定為 wrap_content, 一同使用 editable android:editable 設定 EditText 是否可輸入文字 enabled android:enabled 設定 EditText 是否可被使用 password android:password 設定輸入文字後, 將文字以密碼文 (*) 方式顯 示於畫面 single line android:singleline 設定 EditText 可輸入的列數,true: 只能一 列 ;false: 可以多列 hint android:hint 設定 EditTex 欄位值為空時, 顯示出提示訊 息

EditText 元件應用 ( 續 ) 新增三個 EditText 設定 hint inputtype

EditText 元件應用 ( 續 )

Button 元件應用 建立 DemoButton App 程式名稱 專案名稱 類別名稱自訂 最小的 SDK 請選擇 Android 2.3.3 以上版本 Complie With 請選 android 4.0.3 版本的 Google APIs 15 Activity Name Layout Name 名稱自訂

Button 元件應用 ( 續 ) Button 語法用法 : <Button>.( 內容 ). /> Ex: <Button> android:id= @+id/( 元件名稱 ) android: 元件屬性 ( 名稱 )= 屬性值 / 內容 /> 例如 : android:text= 按一下 元件屬性 ( 名稱 ) text 屬性值 / 內容 按一下

Button 元件應用 ( 續 ) 新增一個 TextView 與 Button 設定屬性 :id text 等內容

Button 元件應用 ( 續 ) 點擊 Button 元件時, 應該有發現並沒有發生任何變化, 這是因為我們尚未賦予 Button 啟動功能的程式碼 接下來要實作出, 當我們點擊 Button 後, 改變 TextView 的內容 實作 Button 的運作可分成兩種作法 : 傳統式與改良式, 傳統式方法是在 oncreate 中加入 setonclicklistener() 的方法先取得 Button 元件後再來監督按鈕的執行 ; 而改良式的方法是直接實作在 Button 功能上, 換個方式說, 當手機用戶按下按鈕時, 便會直接呼叫該按鈕的方法, 並執行方法裡頭的程式運算動作

Button 元件應用 ( 續 ) 傳統式作法 : 匯入要使用的元件 宣告使用的元件變數名稱 使用監聽方式實現作法

Button 元件應用 ( 續 ) 改良式作法 : 加入 onclick 屬性

Button 元件應用 ( 續 ) 改良式作法 : 名稱為 onclick 設定的名稱

執行結果 :

Button 元件應用 ( 續 ) 傳統式與改良式的執行結果雖然都是相同的, 但改良式的作法除了程式簡潔明瞭之外, 執行的速度上也會比較快 而傳統式的作法, 在程式執行到 oncreate 步驟時, 加入了監聽的方法 setonclicklistener(), 此時 Button 每次都要回報系統 ( 監聽 ), 成功後才執行功能

Share Multi Button 應用 設計播打電話的按鈕介面, 需要下列元件與設定值 : TextView id:textview1 text: hint: @string/txt1 Button * 9 id:btnzero~btnnine txt: @string/btn0 ~ @string/btn9 onclick:button0~button9 Button * 2 id:btntest1( 符號代表 :*)~btntext2( 符號代表 :#) txt: @string/btn10 ~ @string/btn11 onclick:button10~button11

Share Multi Button 應用 ( 續 ) 使用 setonclicklistener() 資料夾 [res/values] 內的 strings.xml 添加內容, 如下 : <string name="txt1"> 電話號碼 :</string> <string name="btn0">0</string> <string name="btn1">1</string> <string name="btn2">2</string> <string name="btn3">3</string> <string name="btn4">4</string> <string name="btn5">5</string> <string name="btn6">6</string> <string name="btn7">7</string> <string name="btn8">8</string> <string name="btn9">9</string> <string name="btn10">*</string> <string name="btn11">#</string>

Share Multi Button 應用 ( 續 ) 資料夾 [res/layout] 內的 activity_main.xml 添加內容, 如下 : <TextView android:id="@+id/textview1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/txt1" android:textcolor="#ffffff" android:textsize="24sp"/> <Button android:id="@+id/btnone" android:layout_width="90dp" android:layout_height="80dp" android:layout_alignbottom="@+id/btntwo" android:layout_toleftof="@+id/btntwo" android:layout_marginright="10dp" android:text="@string/btn1" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn" />

Share Multi Button 應用 ( 續 ) <Button android:id="@+id/btntwo" android:layout_width="90dp" android:layout_height="80dp" android:layout_below="@+id/textview1" android:layout_centerhorizontal="true" android:layout_margintop="20dp" android:text="@string/btn2" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn" /> <Button android:id="@+id/btnthree" android:layout_width="90dp" android:layout_height="80dp" android:layout_marginleft="10dp" android:layout_alignbottom="@+id/btntwo" android:layout_torightof="@+id/btntwo" android:text="@string/btn3" android:textcolor="#ffffff" android:textsize="24sp" <Button android:id="@+id/btnfour" android:layout_width="90dp" android:layout_height="80dp" android:layout_alignbottom="@+id/btnfive" android:layout_toleftof="@+id/btnfive" android:layout_marginright="10dp" android:text="@string/btn4" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/> <Button android:id="@+id/btnfive" android:layout_width="90dp" android:layout_height="80dp" android:layout_below="@+id/btntwo" android:layout_centerhorizontal="true" android:layout_margintop="10dp" android:text="@string/btn5" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/>

Share Multi Button 應用 ( 續 ) <Button android:id="@+id/btnsix" android:layout_width="90dp" android:layout_height="80dp" android:layout_marginleft="10dp" android:layout_alignbottom="@+id/btnfive" android:layout_torightof="@+id/btnfive" android:text="@string/btn6" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/> <Button android:id="@+id/btnseven" android:layout_width="90dp" android:layout_height="80dp" android:layout_alignbottom="@+id/btneight" android:layout_toleftof="@+id/btneight" android:layout_marginright="10dp" android:text="@string/btn7" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/> <Button android:id="@+id/btneight" android:layout_width="90dp" android:layout_height="80dp" android:layout_below="@+id/btnfive" android:layout_centerhorizontal="true" android:layout_margintop="10dp" android:text="@string/btn8" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/> <Button android:id="@+id/btnnine" android:layout_width="90dp" android:layout_height="80dp" android:layout_marginleft="10dp" android:layout_alignbottom="@+id/btneight" android:layout_torightof="@+id/btneight" android:text="@string/btn9" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/>

Share Multi Button 應用 ( 續 ) <Button android:id="@+id/btnstar" android:layout_width="90dp" android:layout_height="80dp" android:layout_alignbottom="@+id/btnzero" android:layout_toleftof="@+id/btnzero" android:layout_marginright="10dp" android:text="@string/btn10" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/> <Button android:id="@+id/btnzero" android:layout_width="90dp" android:layout_height="80dp" android:layout_below="@+id/btneight" android:layout_centerhorizontal="true" android:layout_margintop="10dp" android:text="@string/btn0" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/> <Button android:id="@+id/btnhash" android:layout_width="90dp" android:layout_height="80dp" android:layout_marginleft="10dp" android:layout_alignbottom="@+id/btnzero" android:layout_torightof="@+id/btnzero" android:text="@string/btn11" android:textcolor="#ffffff" android:textsize="24sp" android:onclick="btn"/>

Share Multi Button 應用 ( 續 ) 資料夾 [src] 內的 MainActivity.java 添加內容, 如下 : 匯入使用的元件 import android.view.view; import android.widget.button; import android.widget.textview; 宣告元件變數名稱 private TextView txtshow; private Button btnzero,btnone,btntwo,btnthree,btnfour; private Button btnfive,btnsix,btnseven,btneight,btnnine;

Share Multi Button 應用 ( 續 ) oncreate() 主體位置內添加內容 : // 取得資源類別檔中的介面元件 txtshow=(textview)findviewbyid(r.id.txtshow); btnzero=(button)findviewbyid(r.id.btnzero); btnone=(button)findviewbyid(r.id.btnone); btntwo=(button)findviewbyid(r.id.btntwo); btnthree=(button)findviewbyid(r.id.btnthree); btnfour=(button)findviewbyid(r.id.btnfour); btnfive=(button)findviewbyid(r.id.btnfive); btnsix=(button)findviewbyid(r.id.btnsix); btnseven=(button)findviewbyid(r.id.btnseven); btneight=(button)findviewbyid(r.id.btneight); btnnine=(button)findviewbyid(r.id.btnnine);

Share Multi Button 應用 ( 續 ) oncreate() 位置添加內容 : // 設定 button 元件 Click 事件共用 mylistner btnzero.setonclicklistener(mylistner); btnone.setonclicklistener(mylistner); btntwo.setonclicklistener(mylistner); btnthree.setonclicklistener(mylistner); btnfour.setonclicklistener(mylistner); btnfive.setonclicklistener(mylistner); btnsix.setonclicklistener(mylistner); btnseven.setonclicklistener(mylistner); btneight.setonclicklistener(mylistner); btnnine.setonclicklistener(mylistner);

Share Multi Button 應用 ( 續 ) 實作出 setonclicklistener(mylistner) // 定義 onclick() 方法 private Button.OnClickListener mylistner = new Button.OnClickListener(){ @Override public void onclick(view v){ String s=txtshow.gettext().tostring(); switch (v.getid()){ case R.id.btnZero:{ txtshow.settext(s + "0"); break; } case R.id.btnOne:{ txtshow.settext(s + "1"); break; } case R.id.btnTwo:{ txtshow.settext(s + "2"); break; } case R.id.btnThree:{ txtshow.settext(s + "3"); break;

Share Multi Button 應用 ( 續 ) }; } } case R.id.btnFour:{ txtshow.settext(s + "4"); break; } case R.id.btnFive:{ txtshow.settext(s + "5"); break; } case R.id.btnSix:{ txtshow.settext(s + "6"); break; } case R.id.btnSeven:{ txtshow.settext(s + "7"); break; } case R.id.btnEight:{ txtshow.settext(s + "8"); break; } case R.id.btnNine:{ txtshow.settext(s + "9"); break; }

Share Multi Button 應用 ( 續 ) 設計播打電話的按鈕介面, 需要下列元件與設定值 : TextView id:textview1 text: hint: @string/txt1 Button * 9 id:btnzero~btnnine txt: @string/btn0 ~ @string/btn9 onclick:button0~button9 Button * 2 id:btntest1( 符號代表 :*)~btntext2( 符號代表 :#) txt: @string/btn10 ~ @string/btn11 onclick:button10~button11

模擬器執行結果 :

END