|  | 【程序】点击按钮后弹出对话框 | 
                
          |   一派护法 十九级 | 
              OnClickListener btn2_events = new OnClickListener() {@Override
 public void onClick(View v)
 {
 //Here you must use "MainActivity.this" for the parameter Context.
 //You can not use "getApplicationContext()" any more!
 Dialog dlg = new AlertDialog.Builder(MainActivity.this)
 .setTitle("A question")
 .setMessage("How many people are there in your home?")
 .setPositiveButton("Four", null)
 .setNegativeButton("Three", null)
 .create();
 dlg.show();
 }
 };
 findViewById(R.id.button2).setOnClickListener(btn2_events);
 | 
                
          |   一派护法 十九级 | 
              在界面中创建button2后就可以看到效果
 | 
                
          |   一派护法 十九级 | 
              .setPositiveButton("Four", null)第二个参数可以设置点击按钮后的事件,
 一般是new OnClickListener() {},里面一些事件比如onClick,这个和button2那个差不多
 
 | 
                
          |   一派护法 十九级 | 
              .setPositiveButton("确定", new DialogInterface.OnClickListener() { 
 @Override
 public void onClick(DialogInterface dialog, int which) {
 // TODO Auto-generated method stub
 }
 })
 
 | 
                
          |   一派护法 十九级 | 
              回复:5楼OnClickListener变成了DialogInterface.OnClickListener
 View v变成了DialogInterface dialog, int which
 |