zoukankan      html  css  js  c++  java
  • AlertDialog错误

    Unable to add window token null is not for an application 
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(Service_Activity.this);
    // 这里使用getApplicationContext() 报错 必须使用当前activity。

    -----------------------------------------------------------------------------------------------------------------------------------------------------------

    textView1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
               
                    AlertDialog.Builder localBuilder = new AlertDialog.Builder(Service_Activity.this);
                     localBuilder.setTitle("编辑地址").setIcon(R.mipmap.bianji);
    //
    final LinearLayout layout_alert= (LinearLayout) getLayoutInflater().inflate(R.layout.layout_alertservicejiekou, null); localBuilder.setView(layout_alert); localBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                  // 这里使用(LinearLayout) getLayoutInflater().inflate(R.layout.layout_alertservicejiekou, null).findViewByid(R.id.edit1)
                 // .getText().toString()是得不到数据的
    EditText edit1
    = (EditText) layout_alert.findViewById(R.id.edit1); System.out.println("***out"+edit1.getText().toString()); textView1.setText(edit1.getText().toString().trim()); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) { } }).create().show();

     ------------------------------------------------------------------------------------------------------------------

    1.这里的type初始值为null,则在第一次点击是toast的值是*null,然后选择tsg,那么下一次toast值才是tsg,总是得不到本次选择的值.?

    在没有完成alertdialog选择时,程序就往下跑去了…… 吧操作写在alert里面吧,感觉又不大好……

     imageView1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder localBuilder = new AlertDialog.Builder(MainActivity.this);
                    final String[] arrayOfString = { "ATPCU", "C2CU", "SDP", "TSG", "COMC","BTM" };
                    localBuilder.setTitle("选择模块").setIcon(R.mipmap.ic_launcher).setItems(arrayOfString, new DialogInterface.OnClickListener()
                    {
                        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
                        {
                            //  Toast.makeText(MainActivity.this, "你选择了: " + arrayOfString[paramAnonymousInt], Toast.LENGTH_SHORT).show();
    
    
                            type=arrayOfString[paramAnonymousInt];
                        }
                    }).create().show();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Toast.makeText(getApplicationContext(),"*"+type,Toast.LENGTH_SHORT).show();
                }
            });
    
     AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
        localBuilder.setTitle("简单对话框");
        localBuilder.setIcon(2130903040);
        localBuilder.setMessage("1+1=2 ?");
        localBuilder.setPositiveButton("是", new DialogInterface.OnClickListener()
        {
          public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
          {
            Toast.makeText(AlertActivity.this, "回答正确", 0).show();
          }
        });
        localBuilder.setNegativeButton("不是", new DialogInterface.OnClickListener()
        {
          public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
          {
            Toast.makeText(AlertActivity.this, "回答错误 重新选中", 0).show();
          }
        });
        localBuilder.create().show();
    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    【Netty之旅四】你一定看得懂的Netty客户端启动源码分析!
    Netty之旅三:Netty服务端启动源码分析,一梭子带走!
    【原创】经验分享:一个Content-Length引发的血案(almost....)
    Netty之旅二:口口相传的高性能Netty到底是什么?
    Java解压和压缩带密码的zip文件过程详解
    SQLServer安装教程(史上最详细版本)
    26.Vue技术栈开发实战-项目部署
    25.Vue技术栈开发实战-多Tab页开发
    6-6 创建产品卡片组件(1)
    6-5 创建垂直网格组件
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/6131497.html
Copyright © 2011-2022 走看看