• android Dialog


     Dialog

      

    package com.example.dialogdemol;
    
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnClickListener;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        }
    
        /**
         * 显示标准的对话框    
         * @param view
         */
        public void btnDialog(View view) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setPositiveButton("確定", listener);
            builder.setNegativeButton("取消", listener);
            // 设置 点击返回键或者对话框之外的区域能否让对话框消失
            // 即是否能够中断对话框
            builder.setCancelable(false);
            builder.show();
        }
    
        private DialogInterface.OnClickListener listener = new OnClickListener() {
    
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    Toast.makeText(getApplicationContext(), "确定点击", Toast.LENGTH_SHORT).show();
                    break;
                case DialogInterface.BUTTON_NEGATIVE:
                    Toast.makeText(getApplicationContext(), "取消点击", Toast.LENGTH_SHORT).show();
                    break;
    
                default:
                    break;
                }
            }
        };
    
        /**
         * 自定义Dialog
         * 
         * @param view
         */
        @SuppressLint("InflateParams")
        public void btnMyDialog(View view) {
    
            final AlertDialog dialog = new AlertDialog.Builder(this).create();
            LayoutInflater inflater = LayoutInflater.from(this);
            View dialogView = inflater.inflate(R.layout.dialog_layout, null);
            final EditText editText = (EditText) dialogView.findViewById(R.id.editText);
            Button btnOk = (Button) dialogView.findViewById(R.id.btnOK);
            btnOk.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), editText.getText().toString().trim(), Toast.LENGTH_SHORT)
                            .show();
                    ;
                    dialog.dismiss();
                }
            });
            dialog.setView(dialogView);
            dialog.show();
        }
    
    }
  • 相关阅读:
    [UE4]利用取模运算达到循环遍历数组的目的
    RESTful登录设计(基于Spring及Redis的Token鉴权)
    Nginx/LVS/HAProxy负载均衡软件的优缺点详解
    业务中使用分布式的场景
    mycat系列-Mycat 分片规则
    MyCat
    mysql 分区说明
    mysql 表分区 查看表分区 修改表分区
    MySql 分区 分库 分表
    tomcat7部署多个web应用不同编码,端口
  • 原文地址:https://www.cnblogs.com/newlangwen/p/5539016.html
Copyright © 2020-2023  润新知