

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、上海電力學(xué)院嵌入式WebOS應(yīng)用開發(fā)實(shí)驗(yàn)報(bào)告 實(shí)驗(yàn)名稱: 使用Android Developer SDK開發(fā)應(yīng)用程序 專 業(yè): 姓 名: 班 級: 學(xué) 號: 一、 作品的運(yùn)行環(huán)境及安卓SDK基礎(chǔ)操作SDK Android Developer是一款在windows系統(tǒng)上運(yùn)行的針對Android應(yīng)用開發(fā)的谷歌官方軟件(需要JAVA環(huán)境支持)。1、導(dǎo)入工程 2、建立虛擬機(jī) 在運(yùn)行虛擬機(jī)是為保證機(jī)器的順暢運(yùn)行建議選擇分辨率較低的虛擬機(jī),但是其RAM最好設(shè)為512MB,因?yàn)椴糠殖绦蛉绻{(diào)用資源過大會導(dǎo)致虛擬機(jī)無法運(yùn)行.3、虛擬機(jī)界面二、 作品介紹我的應(yīng)用是一個計(jì)算器。能實(shí)現(xiàn)包括小數(shù)的加減乘除運(yùn)算,結(jié)果過
2、大會自動用科學(xué)記數(shù)法表示,另外還有退格跟清屏功能鍵。三、 編程以及運(yùn)行調(diào)試(一)、在MyDesktop主界面中添加應(yīng)用圖標(biāo)1。 首先在我的桌面上添加你應(yīng)用的圖標(biāo)以及文字,雙擊圖標(biāo)后就可以看見對應(yīng)的代碼,可直接在代碼中進(jìn)行修改圖片文字的大小顏色等等。以下是對應(yīng)圖像圖標(biāo)的代碼圖片可以在左側(cè)的選項(xiàng)中自行進(jìn)行挑選;也可以添加自己的圖片,只要將圖片放到對應(yīng)的文件夾之下在刷新就可以,但不建議放分辨率過高圖片可能會出現(xiàn)超出界面的等錯誤。(二)、在res/layout目錄下新建。xml文件,由于計(jì)算器的按鈕很多,要在xml界面中添加排版: xml代碼首末的 /AbsoluteLayout> 格式較為自由
3、可以直接在界面中拖動圖標(biāo)位置以及修改大小,而其他layout則更會自動排列,各有優(yōu)劣。(三)、在src/weibo.test。ui目錄下新建。java文件,計(jì)算器的按鈕算法等都在此實(shí)現(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; / 點(diǎn)private Button bt_clear; / 清除private EditText et_play; / 顯示private String str_oper = ”+”; / 運(yùn)算符p
21、rivate StringBuffer str_display = new StringBuffer();; / 顯示private String str_result; / 結(jié)果顯示private double num1;private double num2;private boolean flag = true; / 小數(shù)點(diǎn)個數(shù)開關(guān)控制;private boolean b_sub, b_mul, b_div; / 運(yùn)算符開關(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 (?。╯
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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- obe教改課題申報(bào)書
- 申報(bào)課題的書籍有哪些書
- 小學(xué)語文縣級課題申報(bào)書
- 新苗課題申報(bào)書模板
- 個人租房合同范本微云
- 初中數(shù)學(xué)課題申報(bào)書模板
- 合同范本紙張
- 合資協(xié)議合同范本模板
- 企業(yè)用工陰陽合同范本
- 合伙競拍合同范本
- 2025年安全員C證(專職安全員)考試題庫
- 醫(yī)療衛(wèi)生系統(tǒng)招聘考試(中醫(yī)學(xué)專業(yè)知識)題庫及答案
- 貴州省貴陽市2024-2025學(xué)年九年級上學(xué)期期末語文試題(含答案)
- 小巴掌童話課件
- 教科版六年級科學(xué)下冊全冊教學(xué)設(shè)計(jì)教案
- 2024年青島遠(yuǎn)洋船員職業(yè)學(xué)院高職單招語文歷年參考題庫含答案解析
- 定額〔2025〕1號文-關(guān)于發(fā)布2018版電力建設(shè)工程概預(yù)算定額2024年度價格水平調(diào)整的通知
- 《moldflow學(xué)習(xí)資料》課件
- 2024建筑施工安全生產(chǎn)隱患識別圖合集
- 2025年江蘇南京技師學(xué)院招聘工作人員19人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025中國移動安徽分公司春季社會招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
評論
0/150
提交評論