

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、上海電力學(xué)院嵌入式WebOS應(yīng)用開發(fā)實驗報告 實驗名稱: 使用Android Developer SDK開發(fā)應(yīng)用程序 專 業(yè): 姓 名: 班 級: 學(xué) 號: 一、 作品的運行環(huán)境及安卓SDK基礎(chǔ)操作SDK Android Developer是一款在windows系統(tǒng)上運行的針對Android應(yīng)用開發(fā)的谷歌官方軟件(需要JAVA環(huán)境支持)。1、導(dǎo)入工程 2、建立虛擬機 在運行虛擬機是為保證機器的順暢運行建議選擇分辨率較低的虛擬機,但是其RAM最好設(shè)為512MB,因為部分程序如果調(diào)用資源過大會導(dǎo)致虛擬機無法運行.3、虛擬機界面二、 作品介紹我的應(yīng)用是一個計算器。能實現(xiàn)包括小數(shù)的加減乘除運算,結(jié)果過
2、大會自動用科學(xué)記數(shù)法表示,另外還有退格跟清屏功能鍵。三、 編程以及運行調(diào)試(一)、在MyDesktop主界面中添加應(yīng)用圖標1。 首先在我的桌面上添加你應(yīng)用的圖標以及文字,雙擊圖標后就可以看見對應(yīng)的代碼,可直接在代碼中進行修改圖片文字的大小顏色等等。以下是對應(yīng)圖像圖標的代碼圖片可以在左側(cè)的選項中自行進行挑選;也可以添加自己的圖片,只要將圖片放到對應(yīng)的文件夾之下在刷新就可以,但不建議放分辨率過高圖片可能會出現(xiàn)超出界面的等錯誤。(二)、在res/layout目錄下新建。xml文件,由于計算器的按鈕很多,要在xml界面中添加排版: xml代碼首末的 /AbsoluteLayout> 格式較為自由
3、可以直接在界面中拖動圖標位置以及修改大小,而其他layout則更會自動排列,各有優(yōu)劣。(三)、在src/weibo.test。ui目錄下新建。java文件,計算器的按鈕算法等都在此實現(xiàn)。(三)、聲明工程名1、在應(yīng)用中有三處需要聲明,首先是在AndroidManifest.xml2、然后是在MainActivity。java 四、 代碼展示(一)、。xml界面代碼<?xml version=”1.0" encoding="utf8”?<LinearLayout xmlns:android=”http://apk/res/and
4、roid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation=”vertical" <TableLayout android:id=”+id/tableLayout1” android:layout_width=”match_parent” android:layout_height="wrap_content" android:collapseColumns="4”
5、<TableRow android:id=”+id/tableRow_et” android:layout_width=”fill_parent" android:layout_height="fill_parent" EditText android:id="+id/et" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_span=”4” android:focusable=
6、”false” android:gravity=”right" android:inputType="text" android:singleLine="true" > /EditText /TableRow <TableRow android:id=”+id/tableRow1” android:layout_width=”fill_parent" android:layout_height=”fill_parent” > <Button android:id="+id/bt_7" and
7、roid:layout_width=”80px" android:layout_height="80px" android:text="7” /> Button android:id=”+id/bt_8” android:layout_width="80px” android:layout_height="80px" android:text="8" / Button android:id=”+id/bt_9” android:layout_width="1px” android:layo
8、ut_height="80px” android:text=”9" / <Button android:id="+id/bt_back" android:layout_width=”80px" android:layout_height="80px" android:text="back” / /TableRow> TableRow android:id=”+id/tableRow2" android:layout_width="fill_parent" android:l
9、ayout_height="fill_parent" > Button android:id="+id/bt_4" android:layout_width="80px" android:layout_height="80px" android:text=”4" / <Button android:id=”+id/bt_5" android:layout_width="80px" android:layout_height=”80px” android:text=
10、”5" /> Button android:id=”+id/bt_6” android:layout_width="80px" android:layout_height="80px” android:text="6" / Button android:id="+id/bt_divide" android:layout_width="80px" android:layout_height=”80px” android:text=”/” / </TableRow TableRow an
11、droid:id="+id/tableRow3” android:layout_width=”fill_parent" android:layout_height="fill_parent" <Button android:id="+id/bt_1" android:layout_width=”80px" android:layout_height=”80px" android:text=”1" / <Button android:id=”+id/bt_2" android:layo
12、ut_width=”80px" android:layout_height=”80px" android:text="2" /> Button android:id=”+id/bt_3” android:layout_width="80px" android:layout_height=”80px” android:text=”3" /> Button android:id="+id/bt_multiply” android:layout_width=”80px" android:layout
13、_height="80px" android:text=”*” / /TableRow TableRow android:id="+id/tableRow4" android:layout_width=”fill_parent" android:layout_height="fill_parent" > Button android:id=”+id/bt_0" android:layout_width="50px” android:layout_height="80px” android:
14、text=”0" /> Button android:id=”+id/bt_point" android:layout_width="50px" android:layout_height=”80px” android:text=”.” /> Button android:id="+id/bt_add” android:layout_width="50px" android:layout_height="80px” android:text=”+" / <Button android:i
15、d="+id/bt_sub” android:layout_width=”50px” android:layout_height=”80px" android:text=”" / </TableRow <TableRow android:id="+id/tableRow4" android:layout_width="fill_parent” android:layout_height="fill_parent" Button android:id=”+id/bt_equal" android
16、:layout_width=”fill_parent” android:layout_height="fill_parent” android:layout_span="3" android:text="=" / <Button android:id=”+id/bt_clear" android:layout_width=”50px" android:layout_height=”80px” android:text="clear" / /TableRow> /TableLayout/Line
17、arLayout(二)、.java功能代碼package weibo。test.ui;import java.util。ArrayList;import java.util.List;import android。app.Activity;import android。os。Bundle;import android.view。View;import android。view。View.OnClickListener;import android.widget.Button;import android。widget。EditText;import android.widget。Toast;i
18、mport weibo。lixiaodaoaaa.ui。R;import android.app。Activity;import android.content.Intent;import android。content。pm.PackageManager;import android.os.Bundle;import android。view。KeyEvent;import android.view。View;import android.view.View.OnClickListener;import android。widget。Button;import android。widget。
19、ListView;import com.zsy.flipper.AppInfUtil;import com.zsy。flipper。AppInfo;public class fffActivity extends Activity private Button bt_1;private Button bt_2;private Button bt_3;private Button bt_4;private Button bt_5;private Button bt_6;private Button bt_7;private Button bt_8;private Button bt_9;priv
20、ate Button bt_0;private Button bt_add;private Button bt_sub; / 減private Button bt_multiply; / 乘private Button bt_divide; / 除private Button bt_back;private Button bt_equal; / 等于private Button bt_point; / 點private Button bt_clear; / 清除private EditText et_play; / 顯示private String str_oper = ”+”; / 運算符p
21、rivate StringBuffer str_display = new StringBuffer();; / 顯示private String str_result; / 結(jié)果顯示private double num1;private double num2;private boolean flag = true; / 小數(shù)點個數(shù)開關(guān)控制;private boolean b_sub, b_mul, b_div; / 運算符開關(guān)控制Overridepublic void onCreate(Bundle savedInstanceState)super.onCreate(savedInstan
22、ceState);setContentView(R.layout.activity_fff);bt_0 = (Button) findViewById(R。id.bt_0);bt_1 = (Button) findViewById(R.id.bt_1);bt_2 = (Button) findViewById(R.id.bt_2);bt_3 = (Button) findViewById(R。id.bt_3);bt_4 = (Button) findViewById(R.id。bt_4);bt_5 = (Button) findViewById(R.id.bt_5);bt_6 = (Butto
23、n) findViewById(R.id。bt_6);bt_7 = (Button) findViewById(R。id.bt_7);bt_8 = (Button) findViewById(R。id.bt_8);bt_9 = (Button) findViewById(R.id。bt_9);bt_add = (Button) findViewById(R。id。bt_add);bt_sub = (Button) findViewById(R。id.bt_sub);bt_multiply = (Button) findViewById(R。id.bt_multiply);bt_divide =
24、 (Button) findViewById(R.id.bt_divide);bt_back = (Button) findViewById(R.id.bt_back);bt_equal = (Button) findViewById(R.id。bt_equal);bt_point = (Button) findViewById(R。id.bt_point);bt_clear = (Button) findViewById(R。id.bt_clear);et_play = (EditText) findViewById(R。id.et);et_play。setText(”0");bt
25、_0。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display.append(”0");et_play。setText(str_display.toString()););bt_1.setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append("1");et_play。setText(str_display。toString(
26、););bt_2.setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append("2”);et_play。setText(str_display.toString()););bt_3.setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append("3");et_play。setText(str_display。toS
27、tring(););bt_4.setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append(”4”);et_play.setText(str_display。toString()););bt_5。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append(”5”);et_play.setText(str_display.toString());
28、);bt_6。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append("6”);et_play.setText(str_display。toString()););bt_7。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append(”7");et_play。setText(str_display。toString()
29、;);bt_8。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append(”8");et_play。setText(str_display。toString(););bt_9。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_display。append("9");et_play。setText(str_display。toStr
30、ing()););bt_point。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)if (flag)str_display。append(”。");flag = false;);bt_back。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)if (str_display。length() != 0)str_display.deleteCharAt(str_display。leng
31、th() - 1);et_play。setText(str_display。toString(););bt_add。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_oper = "+";if (!(str_display.toString() = "")num1 += Double。parseDouble(str_display.toString());str_display = new StringBuffer(”");if (!(s
32、tr_result = null))num1 = Double。parseDouble(str_result);str_result = null;et_play。setText(String。valueOf(num1));flag = true;);bt_sub。setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_oper = "-”;if (!b_sub !(str_display.toString() = "")num1 = Double。parseDo
33、uble(str_display。toString();et_play。setText(String.valueOf(num1);str_display = new StringBuffer(”");b_sub = true; elseif (!(str_display.toString() = ”))num1 = Double.parseDouble(str_display.toString();str_display = new StringBuffer(”);if (?。╯tr_result = null)num1 = Double。parseDouble(str_result
34、);str_result = null;et_play.setText(String.valueOf(num1));flag = true;);bt_multiply.setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_oper = "*";if (!b_mul & !(str_display。toString() = "")num1 = Double。parseDouble(str_display.toString());et_play。s
35、etText(String。valueOf(num1));str_display = new StringBuffer("");b_mul = true; elseif (!(str_display.toString() = ”")num1 = Double.parseDouble(str_display。toString();str_display = new StringBuffer(”);if (!(str_result = null)num1 = Double。parseDouble(str_result);str_result = null;et_pla
36、y。setText(String.valueOf(num1));flag = true;);bt_divide.setOnClickListener(new OnClickListener()Overridepublic void onClick(View v)str_oper = "/"if (!b_div && !(str_display.toString() = ”)num1 = Double.parseDouble(str_display.toString());et_play.setText(String.valueOf(num1);str_dis
37、play = new StringBuffer("");b_div = true; elseif (!(str_display。toString() = ""))if (Double.parseDouble(str_display。toString()) = 0)Toast。makeText(fffActivity.this,"除數(shù)不能為0!”, Toast。LENGTH_LONG)。show(); elsenum1 /= Double。parseDouble(str_display。toString());str_display = new StringBuffer(”");if (!(str_result = null))num1 = Double。parseDouble(str_result);str_result = null;et_play.setText(String。valueOf(num1));flag = true;);bt_clear.setOnClickListener(new OnClickLis
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 內(nèi)陸?zhàn)B殖市場趨勢預(yù)測與分析考核試卷
- 化工企業(yè)物流成本分析與控制方法考核試卷
- 廢氣排放考核試卷
- 光學(xué)玻璃微觀缺陷修復(fù)的表面活性劑應(yīng)用研究考核試卷
- 海洋腐蝕機理分析考核試卷
- 入場三級教育培訓(xùn)考核試卷(含答案)
- 2024年度全科專業(yè)基地住培學(xué)員對帶教師資的評價方案
- 環(huán)保知識題庫 (一)
- 植樹節(jié)熱身活動方案
- 永生花促銷活動方案
- 最新纏論基礎(chǔ)知識大全共課件
- SHSG0522023年石油化工裝置工藝設(shè)計包(成套技術(shù))內(nèi)容規(guī)定
- 2022年中國重癥患者轉(zhuǎn)運指南-2
- 中學(xué)生日常行為習(xí)慣養(yǎng)成課題計劃2
- 懸臂澆筑連續(xù)梁梁體鋼筋施工技術(shù)交底
- 滬教牛津版小學(xué)一至六年級英語單詞匯總(最新)
- 計價格(2002)10號文
- 從銷售員到銷售總監(jiān)的六門必修課
- 《云南省建筑工程資料管理規(guī)程應(yīng)用指南)(上下冊)
- 工程更改控制程序DFCPQEOMS-06
- 送電線路工程跨越河流架線施工專項方案
評論
0/150
提交評論