Android狼双岻Message字崙議痩試哘喘
和中厘断氏參android糞箭栖婢幣斤哘議孔嬬?殻會順中噐和?
殻會旗鷹泌和?朔中何蛍嗤旗鷹傍苧?
1 package com.android.messageexample;
2 import android.app.Activity;
3 import android.content.Context;
4 import android.graphics.Color;
5 import android.os.Bundle;
6 import android.os.Handler;
7 import android.os.Looper;
8 import android.os.Message;
9 import android.util.Log;
10 import android.view.View;
11 import android.view.View.OnClickListener;
12 import android.widget.Button;
13 import android.widget.LinearLayout;
14 import android.widget.TextView;
15 public class MessageExample extends Activity implements OnClickListener {
16 private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;
17 private final int FP = LinearLayout.LayoutParams.FILL_PARENT;
18 public TextView tv;
19 private EventHandler mHandler;
20 private Handler mOtherThreadHandler=null;
21 private Button btn, btn2, btn3, btn4, btn5, btn6;
22 private NoLooperThread noLooerThread = null;
23 private OwnLooperThread ownLooperThread = null;
24 private ReceiveMessageThread receiveMessageThread =null;
25 private Context context = null;
26 private final String sTag = "MessageExample";
27 private boolean postRunnable = false;
28
29 /** Called when the activity is first created. */
30 @Override
31 public void onCreate(Bundle savedInstanceState) {
32 super.onCreate(savedInstanceState);
33 context = this.getApplicationContext();
34 LinearLayout layout = new LinearLayout(this);
35 layout.setOrientation(LinearLayout.VERTICAL);
36 btn = new Button(this);
37 btn.setId(101);
38 btn.setText("message from main thread self");
39 btn.setOnClickListener(this);
40 LinearLayout.LayoutParams param =
41 new LinearLayout.LayoutParams(250,50);
42 param.topMargin = 10;
43 layout.addView(btn, param);
44 btn2 = new Button(this);
45 btn2.setId(102);
46 btn2.setText("message from other thread to main thread");
47 btn2.setOnClickListener(this);
48 layout.addView(btn2, param);
49 btn3 = new Button(this);
50 btn3.setId(103);
51 btn3.setText("message to other thread from itself");
52 btn3.setOnClickListener(this);
53 layout.addView(btn3, param);
54 btn4 = new Button(this);
55 btn4.setId(104);
56 btn4.setText("message with Runnable as callback from other thread to main thread");
57 btn4.setOnClickListener(this);
58 layout.addView(btn4, param);
59 btn5 = new Button(this);
60 btn5.setId(105);
61 btn5.setText("main threads message to other thread");
62 btn5.setOnClickListener(this);
63 layout.addView(btn5, param);
64 btn6 = new Button(this);
65 btn6.setId(106);
66 btn6.setText("exit");
67 btn6.setOnClickListener(this);
68 layout.addView(btn6, param);
69 tv = new TextView(this);
70 tv.setTextColor(Color.WHITE);
71 tv.setText("");
72 LinearLayout.LayoutParams param2 =
73 new LinearLayout.LayoutParams(FP, WC);
74 param2.to
相关新闻>>
- 发表评论
-
- 最新评论 更多>>