• AlertDialog的简单使用


     findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
                    dialog.setTitle("title");
                    dialog.setMessage("message");
                    dialog.setButton("去百度", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Uri uri = Uri.parse("http://www.baidu.com");
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            MainActivity.this.startActivity(intent);
                        }
                    });
                    dialog.setButton2("关闭", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
    
                        }
                    });
                    dialog.show();
                }
            });
    

      调用一个AlertDialog,显示选择跳到baidu首页,关闭则不做任何事情

      view.findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LayoutInflater inflater1 = getActivity().getLayoutInflater();
                    final View View_Dialog1 = inflater.inflate(R.layout.fragment_main, null);
                    final EditText text = (EditText) View_Dialog1.findViewById(R.id.fragment_edit);
                    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
                    dialog.setView(View_Dialog1);
                    dialog.setTitle("title");
                    dialog.setButton("Do a toast", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String str = text.getText().toString();
                            Toast.makeText(getActivity(), "this is a ...... " + str, Toast.LENGTH_SHORT).show();
                        }
                    });
                    dialog.show();
                }
            });
    

     自定义一个布局文件去加载。获得布局文件中的控件,并获得edittext的值。

  • 相关阅读:
    jenkins GitHub 自动触发
    rabbitmq web管理
    系统编码,文件编码,python编码
    反转二叉树
    从右边看二叉树
    python pyenv
    js 闭包
    git review & devops过程
    centos7搭建自己的yum源
    优先级队列PriorityQueue 测试,会自动排序
  • 原文地址:https://www.cnblogs.com/lyxin/p/5799591.html
Copyright © 2020-2023  润新知