zoukankan      html  css  js  c++  java
  • 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()方法显示该按钮。

    运行结果:

  • 相关阅读:
    第几天?
    农历02__资料
    农历01
    VC6_预编译头
    QWebEngine_C++_交互
    Qt570_CentOS64x64_02
    Qt570_CentOS64x64_01
    QWebEngineView_CssVariables
    Windows__书
    Win7SDK
  • 原文地址:https://www.cnblogs.com/mstk/p/3460311.html
Copyright © 2011-2022 走看看