作法
1). 單項標準作法
2). 多項使用switch作法
//=============================================================
1). 單項標準作法
public class DeviceInfo2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 找到元件資源
Button button_info1 = (Button) findViewById(R.id.main_submit_info1);
// 設定按鍵觸發的method
button_info1.setOnClickListener(listDeviceInfo);
}
private Button.OnClickListener listDeviceInfo = new Button.OnClickListener() {
@Override
public void onClick(View v) {
// 宣告intent,並指定要啟動的class
Intent intent = new Intent(DeviceInfo2.this, mService.class);
// 以startservice方式啟動intent
startService(intent);
}
};
}
//=============================================================
2). 多項使用switch作法
public class DeviceInfo2 extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 找到元件資源
Button button_info1 = (Button) findViewById(R.id.main_submit_info1);
button_info1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.main_submit_info1:
// 宣告intent,並指定要啟動的class
Intent intent = new Intent(DeviceInfo2.this, mService.class);
// 以startservice方式啟動intent
startService(intent);
break;
}
}
code那些特別表示方法 你是用!?
回覆刪除我是有google過,但特殊語言 就會怪怪的~"~
聽不懂..
刪除什麼叫做code那些特別表示方法?
作者已經移除這則留言。
回覆刪除就 程式碼啊,那個可以顯示 行號、顏色啊 的那個XD
回覆刪除喔喔你說這阿XD
刪除看這
http://qnworknote.blogspot.tw/2012/06/blog-bloggersyntaxhighlighter.html