alertdialog报错_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(newView.OnClickListener() {
@Overridepublic voidonClick(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("确定", newDialogInterface.OnClickListener()
{public void onClick(DialogInterface paramAnonymousDialogInterface, intparamAnonymousInt)
{
// 这里使用(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("取消", newDialogInterface.OnClickListener()
{public void onClick(DialogInterface paramAnonymousDialogInterface, intparamAnonymousInt)
{
}
}).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("是", newDialogInterface.OnClickListener()
{public void onClick(DialogInterface paramAnonymousDialogInterface, intparamAnonymousInt)
{
Toast.makeText(AlertActivity.this, "回答正确", 0).show();
}
});
localBuilder.setNegativeButton("不是", newDialogInterface.OnClickListener()
{public void onClick(DialogInterface paramAnonymousDialogInterface, intparamAnonymousInt)
{
Toast.makeText(AlertActivity.this, "回答错误 重新选中", 0).show();
}
});
localBuilder.create().show();
alertdialog报错_AlertDialog错误相关推荐
- alertdialog报错_AlertDialog异常:Resources$NotFoundException: Resource ID #0x0 in AlertDialog
背景介绍 今天需要对弹出式对话框进行重构,即单独提出这个对话框,然后获取对话框单击的值.由于当前项目不能随意修改所以只有新建一个类进行修改了. 代码如下: public class MyDialogW ...
- alertdialog报错_alertdialog创建
看你的是哪种了,你自己看看下面我刚写的 private AlertDialog mDialog; private String[] mData = new String[26]; /** * 第一种 ...
- 使用cmd打开java文件,报错:“错误,编码GBK的不可映射字符”
使用cmd打开java文件,报错:"错误,编码GBK的不可映射字符" 今天使用EditPlus写了一个小程序,用cmd运行时报错--"错误,编码GBK的不可映射字符&qu ...
- ERROR 1136 (21S01): MySQL 的报错: 错误 1136(21S01): 列的计数 与 value 的计数 不相符 在第四行。
MySQL 的报错: 错误 1136(21S01): 列的计数 与 value 的计数 不相符 在第四行. desc product+-----------+-------------+------+ ...
- 关于安装TortoiseSVN.msi 报错2203错误
关于安装TortoiseSVN.msi 报错2203错误 安装svn总是报如下错误,怎么解决? 解决方法: ⑴ 修改用户变量 ① 计算机 -> 属性 -> 高级系统设置 -> 环境变 ...
- pom文件报错,错误如下:(org.apache.maven.project.MavenProject,org.apache.maven.archiver.MavenArchiveConfigurat
导入新项目时,pom文件报错,错误如下: org.apache.maven.archiver.MavenArchiver.getManifest (org.apache.maven.project.M ...
- SpringCloud工作笔记087---SpringBoot启动报错:IDEA 错误: 找不到或无法加载主类 解决方法_connected to the target VM, address:
技术交流QQ群[JAVA,C++,Python,.NET,BigData,AI]:170933152 idea 直接运行 springbootAplication 启动类,无法启动web项目,也没有报 ...
- 解决CPLEX安装后无法运行代码,报错乱码(错误显示:ÔËÐÐÅäÖá°配置 1¡±²»´æÔڡ£)
解决CPLEX安装后无法运行代码,报错乱码(错误显示:ÔËÐÐÅäÖá°配置 1¡±²»´æÔڡ£) CPLEX错误显示如下: 解决方法: 重命名"配置 1"为"Conf ...
- Matlab报错:错误使用 rgb2gray>parse_inputs (第 79 行) MAP 必须为 m x 3 的数组。请对 RGB 和灰度图像使用 im2gray。
拟解决问题: Matlab报错:错误使用 rgb2gray>parse_inputs (第 79 行) MAP 必须为 m x 3 的数组.请对 RGB 和灰度图像使用 im2gray. 下述程 ...
最新文章
- 写好 Python 代码的几条原则
- 在 Spring Boot 中,如何干掉 if else!
- centos6.4 安装mysql
- 【sublime Text】sublime Text3安装可以使xml格式化的插件
- Nginx 代理 WebSocket
- Gym 101964 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2018)
- 牛客题霸 NC3 链表中环的入口结点
- checkboxlist与数组结合用的技
- php开发支付宝支付密码忘记了怎么办_密码箱忘记密码怎么办?密码箱解锁方法大全...
- 设计模式实践系列 (3) - 装饰模式 ( Decorator )
- GIT学习(二)--Git分布式的好处
- webgl与opengl技术资讯
- vue的h函数_Vue中render中的h箭头函数
- mac下git安装与使用
- minecraft_如何使用MultiMC管理Minecraft实例和模组
- 微星主板黑苹果_黑苹果配件选择精细篇
- numpy: np.asarray 函数
- 网络推广100种方法
- JavaScript实现左右分栏宽度拉伸
- RLC串联电路截止频率