AlertDialog.Builder弹出对话框

在Android中,弹出对话框使用AlertDialog.Builder方法。

		   new AlertDialog.Builder(MainActivity.this).setTitle("本机设置")
		   		.setView(view)
		   		.setPositiveButton("确定",new DialogInterface.OnClickListener() {   
		               
		            @Override  
		            public void onClick(DialogInterface v, int arg1){ 
	                
		                address_client = spn_client_ip.getSelectedItem().toString();
		                port_client = Integer.parseInt(edt_client_port.getText().toString()); 
		                write_ip();
		                
		            } 
		   
		   		}).show();

其中,view是inflater.inflate的一个xml布局文件:

final View view = inflater.inflate(R.layout.dialog_client, null);

 .setPositiveButton()是监听positive button被按下的事件,new DialogInterface.OnClickListener()是该事件的Listener。

如果需要negative button,还可以setNegativeButton()。

.show()方法显示该按钮。

运行结果:

 

posted @ 2013-12-05 20:40  MSTK  阅读(1168)  评论(0编辑  收藏  举报