寫這一系列文章是為了證明一個素人(世俗謂之"無經驗可"),能否循序漸進完成Android APP開發(遠目......),其中也可能經歷感興趣-->想放棄-->感興趣-->想放棄的無限迴圈。為了怕自己很快就放棄,決定把過程記錄下來,就做為素人挑戰各行各業辛勞企劃的第一發。(意思是還有別發s)
開工。
先從一個BMI專案模仿開始,利用:
1. EditText+(EditText)轉型語法
2. float
3. Log.d
4. 把計算完的BMI值丟到Bundle包裹塞到Intent裡
5. 生成Intent丟到下一個ResultActivity
結果長這樣:
EditText w = (EditText)findViewById(R.id.weight);模擬器
EditText h = (EditText)findViewById(R.id.height);
float weight = Float.parseFloat(w.getText().toString());
float height = Float.parseFloat(h.getText().toString());
height = height/100;
float bmi = weight/(height*height);
Log.d("BMI", bmi+"");
Intent intent
= new Intent(this, ResultActivity.class);
Bundle b = new Bundle();
b.putFloat("BMI", bmi);
intent.putExtras(b);
startActivity(intent);
就這樣,生命中第一個小程式誕生了。
這麼簡單的小程式,花了我四堂課學習,加上數十次"Unfortunately, xxx has stopped "。不得不說,這是一個很有原則的語言,一個地方錯就不能跑,吾人是該學習謹言慎行了。
沒有留言:
張貼留言