下面是比較完整的代碼,如果認為有問題的話,大家可以給我點意見。
- public class MenuActivity extends Activity implements Runnable, OnClickListener {
- /** Called when the activity is first created. */
- private static final String TAG = MenuActivity.class.getSimpleName();
- private final int HANDLER_OF_SUCCESS = 0;
- private Button go_query;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.menu);
- go_query = (Button) findViewById(R.id.go_query);
- go_query.setOnClickListener(this);
- Thread thread = new Thread(this);
- thread.start();
- }
- public void run() {
- // TODO Auto-generated method stub
- sendMsg(HANDLER_OF_SUCCESS, new Bundle());
- }
- private void sendMsg(int flag, Bundle, bundle) {
- Message msg = new Message();
- msg.what = flag;
- msg.setData(bundle);
- handler.sendMessage(msg);
- }
- private Handler handler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case HANDLER_OF_SUCCESS:
- break;
- }
- }
- };
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- switch (v.getId()) {
- case R.id.go_query:
- startActivity(new Intent().setClass(this, TextActivity.class));
- break;
- }
- }
- }
複製代碼 |