JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java ME、Google Android 平台與 JavaCard 討論區 » Android  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
作者 Re:如何在接收到封包時更新UI元件 [Re:罪惡感]
罪惡感





發文: 13
積分: 0
於 2013-09-11 16:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
因為我如果更改成這樣把註冊移到主執行緒執行也是會遇到關閉的問題

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.example.test2;
//------------------import------------------//
import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
//------------------主要介面------------------//
public class MainActivity extends Activity {
 
  private Dialog mLoginDlg;
  private ImageButton Config_btn;
  private TextView NowTemp_Rul;
  private TimerReceiver receiver;
//------------------初始創建執行onCreat方法------------------//
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findView();
    registerTimerReceiver();
  }
 
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
 
  //------------------載入所需元件及註冊------------------//
  private void findView() {
    //
    ImageButton Config_btn = (ImageButton) findViewById(R.id.Config_btn);
    TextView NowTemp_Rul = (TextView)findViewById(R.id.NowTemp_Rul);
    //
    Config_btn.setOnClickListener(new OnClickListener() {// Config_btn被按下後轉跳到config介面
          public void onClick(View arg0) {
            Intent Configintent = new Intent(MainActivity.this, config.class);
            startActivity(Configintent);
          }
        });
    Intent intent = new Intent(MainActivity.this,TimerService.class);
    startService(intent);
  
  }
 
  //------------------退出程式時執行onDestroy方法------------------//
  public void onDestroy() {
    super.onDestroy();
    // 解除BroadcastReceiver的註冊
    unregisterReceiver(receiver);
  }
  
  public void registerTimerReceiver() {
    // 設定只攔截會發送指定字串的 Broadcast
    IntentFilter filter = new IntentFilter(TimerService.TIMER_ACTION);
    receiver = new TimerReceiver();
    // 註冊BroadcastReceiver,當欲攔截的Broadcast發送過來時,
    // 會呼叫對應的onReceive()
    registerReceiver(receiver, filter);
  }
 
  public class TimerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, final Intent intent) {
      NowTemp_Rul.setText(String.valueOf(intent.getExtras().getInt("Temp")));
    }  
  }
}


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2250 如何在接收到封包時更新UI元件 罪惡感 7971 2013-09-10 19:43
2097 Re:如何在接收到封包時更新UI元件 cutebaby 26 2013-09-10 22:49
2107 Re:如何在接收到封包時更新UI元件 lnmlee 324 2013-09-10 23:46
2094 Re:如何在接收到封包時更新UI元件 henry4343 245 2013-09-11 10:42
2091 Re:如何在接收到封包時更新UI元件 lnmlee 322 2013-09-11 11:10
2090 Re:如何在接收到封包時更新UI元件 罪惡感 2555 2013-09-11 16:32
2017 Re:如何在接收到封包時更新UI元件 cutebaby 49 2013-09-12 07:14
2103 Re:如何在接收到封包時更新UI元件 罪惡感 4437 2013-09-12 15:49
» JWorld@TW »  Java ME、Google Android 平台與 JavaCard 討論區 » Android

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8