the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
来源:互联网 发布:程序员常用的工具 编辑:程序博客网 时间:2024/05/16 16:23
安卓AlertDialog的使用,但是却出现了该错误:the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined,我的代码如下:
protected void showChangTextSizeDialog() {
AlertDialog.Builder builder = new Builder(NewsDetailActivity.this);
builder.setTitle("设置文字大小");
String[] items ={"超大字号","大字号","正常字号","小字号","超小字号"};
builder.setSingleChoiceItems(items, realTextSize, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tempTextSize = which;
}
});
builder.setNegativeButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
realTextSize = tempTextSize;
//设置文字大小
changTextSize(realTextSize);
}
});
builder.setPositiveButton("取消", null);
builder.show();
}
/**
* 设置位置大小
* @param realTextSize2
*/
protected void changTextSize(int realTextSize) {
// TODO Auto-generated method stub
switch (realTextSize) {
case 0://超大
settings.setTextSize(TextSize.LARGEST);
break;
case 1:
settings.setTextSize(TextSize.LARGER);
break;//大字号
case 2:
settings.setTextSize(TextSize.NORMAL);
break;//正常字号
case 3:
settings.setTextSize(TextSize.SMALLER);
break;//小字号
case 4:
settings.setTextSize(TextSize.SMALLEST);
break;//超小字号
default:
break;
}
查找了AlertDialog的源代码,也没能发现该问题,因为出错的原因是:Builder builder=new Builder(this) 该方法里面的this为当前类OnClickListener的实例,而不是我们想要赋值NewsDetailActivity.this,所以,只需要把this改为NewsDetailActivity.this。
问题解决~
- 兔子--The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined
- the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- 关于解决:the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- The constructor AlertDialog.Builder(***) is undefined
- The constructor WeiboAuth(new View.OnClickListener(){}, String, String, String) is undefined
- The constructor SimpleAdapter(new View.OnClickListener(){},...)is undefined的问题及解决
- 关于“The constructor ArrayAdapter(new View.OnClickListener(){}, int, String[]) is undefined”错误提示的解决办法
- Android listView,自定义Adapter,另The constructor AlertDialog.Builder(MyAdapter) is undefined问题
- The constructor AnimatorSet.Builder(xxx) is undefined错误类型
- The constructor SimpleAdapter(new View.OnClickListener(){}, List<Map<String,Object>>, ..的解决方法
- The constructor SimpleAdapter(new View.OnClickListener(){}, List<Map<String,Object>>,..)解决方法
- The constructor Date() is undefined
- The constructor Date() is undefined
- android异常:The constructor Data() is undefined
- The constructor XMLOutputter(Format) is undefined
- 三、快速学习创建版本库、管理修改、查看状态、分支、标签、变基、克隆远程版本库
- PopupWindow setOutsideTouchable 问题
- MySQL数据表的CRUD(増、删、改、查)操作
- Android: mediaplayer went away with unhandled events
- C++--String类型各种重载函数的实现
- the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- OC学习----可变数组与不可变数组
- Monkey常用命令详解
- Window及document对象
- 正则表达式30分钟入门教程
- 面试题—— 从尾到头打印链表
- 4pda.ru注册验证的解码算法
- C++ 字符串
- 【十二】记录