Chinaunix首页 | 论坛 | 博客
  • 博客访问: 137695
  • 博文数量: 38
  • 博客积分: 1605
  • 博客等级: 上尉
  • 技术积分: 370
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-12 14:59
文章分类

全部博文(38)

文章存档

2013年(3)

2012年(8)

2011年(28)

分类: 嵌入式

2011-06-20 11:35:40

  1. package com.test;

  2. //import java.net.URISyntaxException;

  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.os.Environment;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.Toast;

  10. public class TestActivity1 extends Activity {
  11.     /** Called when the activity is first created. */
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.main);

  16.         Button btn = (Button) this.findViewById(R.id.button1);
  17.         btn.setOnClickListener(new View.OnClickListener() {
  18.             public void onClick(View v) {

  19.                 // Show a hint message box and auto disappear after timeout
  20.                 Toast.makeText(getApplicationContext(), "Hello Android, I am coming....",
  21.                      Toast.LENGTH_LONG).show();                 
  22.             }
  23.         });
  24.     }
  25. }


-----------------------------------------------------------------------------
搞个有按钮的对话框,点击button退出activity.
  1. Dialog dlg = new AlertDialog.Builder(TestActivity1 .this)
  2.                 .setMessage(R.string.hello)
  3.                 .setCancelable(false)   // disable cancel action, hardware back button 
  4.                 .setPositiveButton(R.string.OK,
  5.                         new DialogInterface.OnClickListener() {
  6.                                                         
  7.                             public void onClick(DialogInterface dialog, int which) {
  8.                                  TestActivity1.this.finish();
  9.                             }
  10.                             
  11.                         }).create();
  12.                 
  13.             
  14.             dlg.show();
阅读(6892) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~