Android: "AlertDialog.Builder constructor (new View.OnClickListener () {}) is an undefined error"

I found code to create some input fields, and they are fine, but in this code it just doesn't 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() {}) undefined" , - ".. AlertDialog.Builder(this)), . , "this" -. menuitem, , , (thats what if (editOn == 1)) . , , , - , , !

+4
2

clickListener AlertDialog.Builder.

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

. , MainActivity thy this:

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

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

: AlertDialog show():

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

+16

, , , - !:)

AlertDialog.Builder builder = new AlertDialog.Builder(((MainActivity ) getActivity()));
        builder.setMessage( "No connectivity").setCancelable(false)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog,int id) {
                }
            });
        AlertDialog alert = builder.create();
        alert.show(); 
0

All Articles