搜尋此網誌

2010年10月16日 星期六

專業訓結束

一眨眼5週的專業訓又結束了 在這邊的日子過得還不錯 接下來就是要下部隊了 受苦受難的開始orz 離開學校單位 放假時間就開始不固定了 就是用排假的方式 不知道下次放假是什麼時候了

2010年9月13日 星期一

新訓

很快的7天的結訓假要尾聲了 時間過得好快阿~接下來就要到專業訓的地方受訓了
新訓的時候 都會覺得7天是相當漫長
還記得剛進來的時候 相當不適應 很多事都會被管 洗澡吃飯時間 都非常的趕 至於打電話是 一直到第四天還第五天才開放 等電話打通的時候 真的會有一種莫名想掉眼淚的衝動 訓練也是非常的辛苦 很多人撐不下去 就退訓了
不過我都把它當作上健身房(只能這麼想了><) 每天都跟同寢互相鼓勵 互相倒數還有幾天放假等 只能說新訓的時候過得非常充實 到了最後結訓那天 真的會開心到跳起來~因為很快的就要出去了 吃很久沒吃過的東西 見很久沒見到的北鼻~謝謝北鼻 在電話裡一直鼓勵我 也寫信給我 讓我有支撐下去的動力^^ 我終於撐過新訓了QQ 接下來就是要度過專業訓了

2010年6月21日 星期一

Android開發-UIImageView


在android上顯示圖片 有兩種方法 一種是直接在xml裡面用imageview 或者 用code的方式來顯示 這和iphone是相似的(xib和code)

首先先把要顯示的圖檔丟到專案中的res/drawable資料夾

接著開始寫程式
方法一:在xml加入imageview
main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
//加入ImageView
<ImageView
android:id="@+id/widget27"
android:layout_width="37px"
android:layout_height="wrap_content"
//one為圖檔的名字
android:src="@drawable/one"
android:layout_x="140px"
android:layout_y="162px"
>
</ImageView>
</AbsoluteLayout>

方法二:用code的方式
ImageView.java

package com.demo.android.imageview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.AbsoluteLayout;
import android.widget.Gallery.LayoutParams;

public class Imageview extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AbsoluteLayout mAbsoluteLayout = new AbsoluteLayout(this);
//產生ImageView object
ImageView imageView = new ImageView(this);
//讀取圖檔
imageView.setImageResource(R.drawable.one);
//設定圖片大小和位置
//AbsoluteLayout.LayoutParams (int width, int height, int x, int y)
//
LayoutParams.WRAP_CONTENT 用圖片的原始大小 x,y為圖片的顯示位置
myview.setLayoutParams(new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,130,192));
mAbsoluteLayout.addView(myview);
setContentView(mAbsoluteLayout);
}
}

2010年6月17日 星期四

Android開發-實際應用(一)基礎代謝率


這次程式是撰寫 計算人的基礎代謝率 其實此程式在iphone已經寫過了 這次因為在練習 所以將此程式又寫了另外一個版本在android上 而寫此程式的目的在於 將之前學過的東西再複習一次 增加熟練度

main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="@+id/height"
android:layout_width="122px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="130px"
android:layout_y="22px"
>
</EditText>
<TextView
android:id="@+id/widget28"
android:layout_width="wrap_content"
android:layout_height="22px"
android:text="Height(cm)"
android:layout_x="40px"
android:layout_y="32px"
>
</TextView>
<TextView
android:id="@+id/widget29"
android:layout_width="wrap_content"
android:layout_height="23px"
android:text="Weight(kg)"
android:layout_x="40px"
android:layout_y="102px"
>
</TextView>
<EditText
android:id="@+id/weight"
android:layout_width="122px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="130px"
android:layout_y="92px"
>
</EditText>
<TextView
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:layout_x="60px"
android:layout_y="162px"
>
</TextView>
<EditText
android:id="@+id/age"
android:layout_width="123px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="130px"
android:layout_y="152px"
>
</EditText>
<RadioGroup
android:id="@+id/myradio"
android:layout_width="288px"
android:layout_height="76px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_x="10px"
android:layout_y="202px"
>
<RadioButton
android:id="@+id/manradio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Man"
>
</RadioButton>
<RadioButton
android:id="@+id/womanradio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Woman"
>
</RadioButton>
</RadioGroup>
<Spinner
android:id="@+id/spinner"
android:layout_width="194px"
android:layout_height="wrap_content"
android:layout_x="120px"
android:layout_y="312px"
>
</Spinner>
<TextView
android:id="@+id/display"
android:layout_width="240px"
android:layout_height="42px"
android:background="#ffff6600"
android:layout_x="40px"
android:layout_y="382px"
>
</TextView>
<Button
android:id="@+id/calculate"
android:layout_width="77px"
android:layout_height="wrap_content"
android:text="calculate"
android:layout_x="30px"
android:layout_y="312px"
android:onClick="Calculate"
>
</Button>
</AbsoluteLayout>

Health.java

package com.android.demo.health;


import java.text.DecimalFormat;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class Health extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findview();
spinnercontent();
setlistener();
}
private EditText Height,Weight,Age;
private TextView display;
private Spinner spinner;
private float a;
private RadioGroup Myradiogroup;
boolean man,woman;
private void findview()
{
Myradiogroup=(RadioGroup)findViewById(R.id.myradio);
Height=(EditText)findViewById(R.id.height);
Weight=(EditText)findViewById(R.id.weight);
Age=(EditText)findViewById(R.id.age);
spinner=(Spinner)findViewById(R.id.spinner);
display=(TextView)findViewById(R.id.display);
}
private RadioGroup.OnCheckedChangeListener changeradio=new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//判斷user是圈選男性或女性
switch(checkedId)
{
case R.id.manradio:
man=true;
break;
case R.id.womanradio:
woman=true;
break;
default:
Toast.makeText(Health.this,"You don't select something else",Toast.LENGTH_LONG).show();
}
}

};
private void setlistener()
{
spinner.setOnItemSelectedListener(spinnerListener);
Myradiogroup.setOnCheckedChangeListener(changeradio);
}
//設定下拉式選單的內容
private void spinnercontent()
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,new String[]{"很少運動或完全沒運動","每週運動1到3次","每週運動3到5次","每週運動6到7次","每天非常重度的運動"});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
//監聽user選了下拉式選單的選項
private Spinner.OnItemSelectedListener spinnerListener= new Spinner.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?>adapterView, View v, int position, long id)
{
String string=adapterView.getSelectedItem().toString();
if(string.equals("很少運動或完全沒運動"))
{
a=(float) 1.2;
}
else if (string.equals("每週運動1到3次"))
{
a=(float)1.375;
}
else if (string.equals("每週運動3到5次"))
{
a=(float)1.55;
}
else if (string.equals("每週運動6到7次"))
{
a=(float)1.725;
}
else
{
a=(float)1.9;
}

}
public void onNothingSelected(AdapterView<?>adapterView)
{
Toast.makeText(Health.this, "You don't select something else", Toast.LENGTH_LONG).show();
}
};
//當user按下calculate按鈕 就執行內部的程式
public void Calculate(View v)
{
//取得user所填入的數字
float height = Float.parseFloat(Height.getText().toString());
float weight = Float.parseFloat(Weight.getText().toString());
int age=Integer.parseInt(Age.getText().toString());
//設定計算數字的格式
DecimalFormat nf = new DecimalFormat("0.00");
//如果user是男性 就以此公式計算
if(man)
{
double manresulta=(double)66+(13.8*weight)+(5.0*height)-(6.8*age);
double manresultb=a*manresulta;
//先將計算後的數字對應我設定的格式 接著將double轉成string 最後顯示出來
display.setText(String.valueOf(nf.format(manresultb)));
}
//如果user是女性 就以此公式計算
if(woman)
{
double womanresulta=(double)655+(9.6*weight)+(1.8*height)-(4.7*age);
double womanresultb=a*womanresulta;
display.setText(String.valueOf(nf.format(womanresultb)));
}

}
}

2010年6月14日 星期一

Android開發-RadioButton


此次程式主要是練習RadioButton的使用方法 並且同樣的使用Toast來顯示 來方便驗證是否正確的監聽到使用者的圈選
此次用RadioGroup將同性質的按鈕歸類為同一類 來達到兩個按鈕互斥(也就是二選一)

main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="320px"
android:layout_height="430px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_x="0px"
android:layout_y="2px"
>
<RadioButton
android:id="@+id/maleradio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Man"
>
</RadioButton>
<RadioButton
android:id="@+id/femaleradio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Woman"
>
</RadioButton>
</RadioGroup>
</AbsoluteLayout>

Radiobutton.java

package com.android.demo.radiobutton;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Radiobutton extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findview();
setlistener();

}
private RadioGroup myradiogroup;
private void findview()
{
myradiogroup=(RadioGroup)findViewById(R.id.radiogroup);
}
private void setlistener()
{
myradiogroup.setOnCheckedChangeListener(changeradio);
}
//監聽radiogroup裡面的radiobutton是否有被使用者圈選
private RadioGroup.OnCheckedChangeListener changeradio=new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//透過id來辨認不同的radiobutton
switch(checkedId)
{
case R.id.maleradio:
Toast.makeText(Radiobutton.this,"You are a Man",Toast.LENGTH_LONG).show();
break;
case R.id.femaleradio:
Toast.makeText(Radiobutton.this,"You are a Woman",Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(Radiobutton.this,"Someting error",Toast.LENGTH_LONG).show();
}
}

};
}