X

Download Android bundle PowerPoint Presentation

SlidesFinder-Advertising-Design.jpg

Login   OR  Register
X


Iframe embed code :



Presentation url :

Home / Science & Technology / Science & Technology Presentations / Android bundle PowerPoint Presentation

Android bundle PowerPoint Presentation

Ppt Presentation Embed Code   Zoom Ppt Presentation

PowerPoint is the world's most popular presentation software which can let you create professional Android bundle powerpoint presentation easily and in no time. This helps you give your presentation on Android bundle in a conference, a school lecture, a business proposal, in a webinar and business and professional representations.

The uploader spent his/her valuable time to create this Android bundle powerpoint presentation slides, to share his/her useful content with the world. This ppt presentation uploaded by onlinesearch in Science & Technology ppt presentation category is available for free download,and can be used according to your industries like finance, marketing, education, health and many more.

About This Presentation

Android bundle Presentation Transcript

Slide 1 - 第三章 手機與PDA行動裝置平台簡介
Slide 2 - 實驗介紹 實驗目的 撰寫程式 “EX03_10” 利用簡單BMI標準體重計算器,示範如何將資料傳遞到下一個Activity。
Slide 3 - 實驗步驟 首先打開 Eclipse 3.5 File → New→ Android Project
Slide 4 - EX03_10 撰寫“EX03_10”程式 在模擬器中執行 情境: 從介面1輸入性別、身高, 把資料傳遞到介面2會輸出 您的標準體重
Slide 5 - 介面 main.xml(1) //設定TextView座標y //設定TextView座標y
Slide 6 - //設定TextView座標y //設定TextView座標y
Slide 7 - 介面 main.xml(3)
Slide 8 - 介面 main.xml(4) TextView TextView物件title TextView物件text1 TextView物件text2 TextView物件text3 Button Button物件button1 RadioGroup RadioGroup物件sex RadioButton RadioButton物件sex1 RadioButton物件sex2 EditText EditText物件名稱為height
Slide 9 - 介面 mylayout.xml(1)
Slide 10 - 介面 mylayout.xml(2) TextView TextView物件text1
Slide 11 - Android程式碼 EX03_10.java Import略 public class EX03_10 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 載入main.xml Layout */ setContentView(R.layout.main); /* 以findViewById()取得Button物件,並加入onClickListener */ Button b1 = (Button) findViewById(R.id.button1); b1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { /*取得輸入的身高*/ EditText et = (EditText) findViewById(R.id.height); double height=Double.parseDouble(et.getText().toString()); //取得身高輸入框的值 /*取得選擇的性別*/ String sex=""; RadioButton rb1 = (RadioButton) findViewById(R.id.sex1); //男的RadioButton if(rb1.isChecked()) //如果選擇的是男的RadioButton { sex=“M”; //sex字串內容為”M” }else{ //否則 sex="F"; //sex字串內容為”F” } /*new一個Intent物件,並指定class*/ Intent intent = new Intent(); intent.setClass(EX03_10.this,EX03_10_1.class); /*new一個Bundle物件,並將要傳遞的資料傳入*/ Bundle bundle = new Bundle(); bundle.putDouble(“height”,height); //傳遞height(身高)的值 bundle.putString(“sex”,sex); //傳遞sex的值(M或F) /*將Bundle物件assign給Intent*/ intent.putExtras(bundle); /*呼叫Activity EX03_10_1*/ startActivity(intent); } }); } }
Slide 12 - public void onClick(View v) { /*取得輸入的身高*/ EditText et = (EditText) findViewById(R.id.height); double height=Double.parseDouble(et.getText().toString()); //取得身高輸入框的值 /*取得選擇的性別*/ String sex=""; RadioButton rb1 = (RadioButton) findViewById(R.id.sex1); //男的RadioButton if(rb1.isChecked()) //如果選擇的是男的RadioButton { sex=“M”; //sex字串內容為”M” }else{ //否則 sex="F"; //sex字串內容為”F” }
Slide 13 - Intent intent = new Intent(); intent.setClass(EX03_10.this,EX03_10_1.class); /*new一個Bundle物件,並將要傳遞的資料傳入*/ Bundle bundle = new Bundle(); bundle.putDouble(“height”,height); //傳遞height(身高)的值 bundle.putString(“sex”,sex); //傳遞sex的值(M或F) bundle.putString(“name”,”陳瑞樂_99”); /*將Bundle物件assign給Intent*/ intent.putExtras(bundle); /*呼叫Activity EX03_10_1*/ startActivity(intent);
Slide 14 - Activity2 /* 取得Intent中的Bundle物件 */ Bundle bunde = this.getIntent().getExtras(); /* 取得Bundle物件中的資料 */ String sex = bunde.getString("sex"); double height = bunde.getDouble("height"); /* 判斷性別 */ String sexText=""; if(sex.equals("M")){ sexText="男性"; }else{ sexText="女性"; }
Slide 15 - /* 設定輸出文字 */ TextView tv1=(TextView) findViewById(R.id.text1); tv1.setText("你是一位"+sexText+"\n你的身高是"+height+ "公分\n你的標準體重是"+weight+"公斤");
Slide 16 - Android程式碼 EX03_10_1.java(1) Import略 public class EX03_10_1 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 載入main.xml Layout */ setContentView(R.layout.myalyout); /* 取得Intent中的Bundle物件 */ Bundle bunde = this.getIntent().getExtras(); /* 取得Bundle物件中的資料 */ String sex = bunde.getString("sex"); double height = bunde.getDouble("height"); /* 判斷性別 */ String sexText=""; if(sex.equals("M")){ sexText="男性"; }else{ sexText="女性"; } /* 取得標準體重 */ String weight=this.getWeight(sex, height); /* 設定輸出文字 */ TextView tv1=(TextView) findViewById(R.id.text1); tv1.setText("你是一位"+sexText+"\n你的身高是"+height+ "公分\n你的標準體重是"+weight+"公斤"); }
Slide 17 - Android程式碼 EX03_10_1.java(2) /* 四捨五入的method */ private String format(double num) { NumberFormat formatter = new DecimalFormat("0.00"); String s=formatter.format(num); return s; } /* 以findViewById()取得Button物件,並加入onClickListener */ private String getWeight(String sex,double height) { String weight=""; if(sex.equals("M")) { weight=format((height-80)*0.7); }else { weight=format((height-70)*0.6); } return weight; } }