zoukankan      html  css  js  c++  java
  • 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的值。

  • 相关阅读:
    Django学习(二) Django框架简单搭建
    Django学习(一) Django安装配置
    Python学习(一) Python安装配置
    注册第一天,纪念一下
    小程序笔记
    详解HTML5中的进度条progress元素简介及兼容性处理
    服务管理
    yum
    管道,输出,管道,重定向,grep
    VIM
  • 原文地址:https://www.cnblogs.com/lyxin/p/5799591.html
Copyright © 2011-2022 走看看