• 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();
    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    安装Visual_Studio的艰辛历程
    桶排序和直接排序的算法和数据结构
    链式队列的c++代码和原理以及编译分析
    C# 利用xmlhttp根据网址调用接口获取数据
    使用 LINQ To SQL 和实体框架实现灵活的数据访问
    K51的安装包和ET199的开发包和示例
    The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[BMS.DataAccess.Models.ServiceTyp
    VS2008中文版中安装 silverlight 3 英文版
    让Windows Server 2008+IIS 7+ASP.NET支持10万个同时请求(转)
    在windows2003+IIS6部署dot net的MVC项目
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/6131497.html
Copyright © 2020-2023  润新知