注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

itas109的博客

http://blog.csdn.net/itas109

 
 
 

日志

 
 

Android : “The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined” error  

2014-03-01 15:17:32|  分类: Android |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
http://stackoverflow.com/questions/19937898/android-the-constructor-alertdialog-buildernew-view-onclicklistener-is

de style=" border: 0px; vertical-align: baseline;margin: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; padding: 0px;"  >View.OnClickListener handleOnClick(final TextView textview) {
return new View.OnClickListener() {
public void onClick(View v) {

if(editOn==1){
textview
.setText("neuer Text");

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert
.setTitle("Hinzufügen");
alert
.setMessage("Name des neuen Eintrags");

final EditText input = new EditText(this);
alert
.setView(input);

alert
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String entryInput = input.getText().toString();
loadUp
(entryInput,"0","1.1.2000");
}
});

alert
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});


}
}
};
}de>

It says, that "The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined" Whenever i try to insert something in ".. new AlertDialog.Builder(this); , then i dont have any errors. I know, that "this" has to refer to something. When i used this code snippet on a menuitem, it works well, but i want to use it whenever i activated my edit button (thats what if(editOn==1) means) and click on a textview. This is kind of confusing i think, but i hope someone out there understand what i need and may help me !

解决:

You are trying to send a clickListener instance to AlertDialog.Builder constructor. 

AlertDialog.Builder alert = new AlertDialog.Builder(this);Try to send your activity's instance. For example if your activity name is MainActivity thy this:

AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);

or:

AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext());

Edit: To show an AlertDialog use its show() method:

AlertDialog dialog = alert.create();

dialog.show();

See docs



  评论这张
 
阅读(830)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018