安卓:"构造AlertDialog.Builder(新View.OnClickListener(){})是未定义"错误 [英] Android : "The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined" error

查看:306
本文介绍了安卓:"构造AlertDialog.Builder(新View.OnClickListener(){})是未定义"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现$ C $下建立一些inputboxes,他们是好的,但在这个code,它只是不工作:

I found the code for building some inputboxes and they are alright, but in this code it just doesnt work:

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) {
                  }
                });


            }
        }
    };
}

它说,即构造AlertDialog.Builder(新View.OnClickListener(){})是未定义 每当我尝试插入的东西......新AlertDialog.Builder();,那么我没有任何错误,我知道这一点。这种有指东西时,我用这个在菜单项code段,它工作得很好,但我想使用它时,我激活了我的编辑按钮(那是什么,如果(篇] == 1)表示),点击一个TextView,这是一种混乱,我认为,但我希望有人在那里知道我需要什么,并且可以帮助我!

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 !

推荐答案

正在试图发送一个clickListener实例 AlertDialog.Builder 的构造。

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

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

尝试发送您的活动的实例。例如,如果你的活动名称为 MainActivity 你这样的:

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

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

编辑::要显示一个 AlertDialog 利用其显示()方法:

To show an AlertDialog use its show() method:

AlertDialog dialog = alert.create();
dialog.show();

<一个href="http://developer.android.com/reference/android/app/AlertDialog.Builder.html#AlertDialog.Builder%28android.content.Context%29">See文档

这篇关于安卓:&QUOT;构造AlertDialog.Builder(新View.OnClickListener(){})是未定义&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆