AlertDialog onclick'i göstermiyor

AlertDialog onclick'i göstermiyor.

Bir düğmeye uzunca bastığınızda, açılan bir iletişim kutusu olmalı, ancak görünmüyor. LongClicklistener'e erişilir, ancak iletişim kutusuna hala gelmiyor.

   //Set Reset Button
    resetBtn = (ImageButton) findViewById(R.id.resetButton);
    resetBtn.setOnLongClickListener(new Button.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialogWrapper.Builder alertDialog = new AlertDialogWrapper.Builder(MainActivity.this);
            alertDialog.setPositiveButton(getString(R.string.MAIN_MENU_RESET_ALERT_YES), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                   //Write your code here to invoke YES event
                    Toast toast = Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_YES), Toast.LENGTH_LONG);
                    toast.show();
                }
            });                alertDialog.setNegativeButton(getString(R.string.MAIN_MENU_RESET_ALERT_NO), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_NO), Toast.LENGTH_SHORT).show();
                    dialog.cancel();
                }
            });
           //Showing Alert Message
            return true;
        }
    });
1

16 cevap

Unuttun

alertDialog.show(); 
1
katma

Unuttun

alertDialog.show(); 
1
katma

You are missing alertDialog.show()

// Set Reset Button 
resetBtn = (ImageButton) findViewById(R.id.resetButton); 
resetBtn.setOnLongClickListener(new Button.OnLongClickListener() {
    @Override 
    public boolean onLongClick(View v) {
        AlertDialogWrapper.Builder alertDialog = new AlertDialogWrapper.Builder(MainActivity.this);
        alertDialog.setPositiveButton(getString(R.string.MAIN_MENU_RESET_ALERT_YES), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
               //Write your code here to invoke YES event 
                Toast toast = Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_YES), Toast.LENGTH_LONG);
                toast.show();
            } 
        });                  
        alertDialog.setNegativeButton(getString(R.string.MAIN_MENU_RESET_ALERT_NO), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_NO), Toast.LENGTH_SHORT).show();
                dialog.cancel();
            } 
        }); 
        /*** Showing Alert Message ***/
        alertDialog.show();
        return true; 
    } 
}); 
1
katma

You are missing alertDialog.show()

// Set Reset Button 
resetBtn = (ImageButton) findViewById(R.id.resetButton); 
resetBtn.setOnLongClickListener(new Button.OnLongClickListener() {
    @Override 
    public boolean onLongClick(View v) {
        AlertDialogWrapper.Builder alertDialog = new AlertDialogWrapper.Builder(MainActivity.this);
        alertDialog.setPositiveButton(getString(R.string.MAIN_MENU_RESET_ALERT_YES), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
               //Write your code here to invoke YES event 
                Toast toast = Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_YES), Toast.LENGTH_LONG);
                toast.show();
            } 
        });                  
        alertDialog.setNegativeButton(getString(R.string.MAIN_MENU_RESET_ALERT_NO), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_NO), Toast.LENGTH_SHORT).show();
                dialog.cancel();
            } 
        }); 
        /*** Showing Alert Message ***/
        alertDialog.show();
        return true; 
    } 
}); 
1
katma

Diyalog gösterme kodundaki ana satırı kaçırdınız ... sadece satırın altına ekleyin

// Showing Alert Message
  alertDialog.show(); 
  return true;
0
katma

Diyalog gösterme kodundaki ana satırı kaçırdınız ... sadece satırın altına ekleyin

// Showing Alert Message
  alertDialog.show(); 
  return true;
0
katma

AlertDialog.show() eksik ve uzun tıkladığınızda uyarının iletişim kutusu örneğine bakın

SingleButtton.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
       //Creating alert Dialog with one Button

        AlertDialog alertDialog = new  
        AlertDialog.Builder(AlertDialogActivity.this).create();

       //Setting Dialog Title
        alertDialog.setTitle("Alert Dialog");

       //Setting Dialog Message
        alertDialog.setMessage("Welcome to Android Application");

       //Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.tick);

       //Setting OK Button
        alertDialog.setButton("OK", new 
        DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,int which) 
                    {
                       //Write your code here to execute after dialog closed
                    Toast.makeText(getApplicationContext(),"You clicked on OK", Toast.LENGTH_SHORT).show();
                    }
                });

       //Showing Alert Message
        alertDialog.show();
        return true;

    }
});


btnAlertTwoBtns.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
       //Creating alert Dialog with two Buttons

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);

       //Setting Dialog Title
        alertDialog.setTitle("Confirm Delete...");

       //Setting Dialog Message
        alertDialog.setMessage("Are you sure you want delete this?");

       //Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.delete);

       //Setting Positive "Yes" Button
        alertDialog.setPositiveButton("YES",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int which) {
                       //Write your code here to execute after dialog
                        Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
                    }
                });
       //Setting Negative "NO" Button
        alertDialog.setNegativeButton("NO",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                       //Write your code here to execute after dialog
                        Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
                        dialog.cancel();
                    }
                });

       //Showing Alert Message
        alertDialog.show();
        return true;

    }
});

btnAlertThreeBtns.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
       //Creating alert Dialog with three Buttons

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                AlertDialogActivity.this);

       //Setting Dialog Title
        alertDialog.setTitle("Save File...");

       //Setting Dialog Message
        alertDialog.setMessage("Do you want to save this file?");

       //Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.save);

       //Setting Positive Yes Button
        alertDialog.setPositiveButton("YES",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,
                            int which) {
                       //User pressed Cancel button. Write Logic Here
                        Toast.makeText(getApplicationContext(),
                                "You clicked on YES",
                                Toast.LENGTH_SHORT).show();
                    }
                });
       //Setting Negative No Button... Neutral means in between yes and cancel button
        alertDialog.setNeutralButton("NO",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,
                            int which) {
                       //User pressed No button. Write Logic Here
                        Toast.makeText(getApplicationContext(),
                                "You clicked on NO", Toast.LENGTH_SHORT)
                                .show();
                    }
                });
       //Setting Positive "Cancel" Button
        alertDialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,
                            int which) {
                       //User pressed Cancel button. Write Logic Here
                        Toast.makeText(getApplicationContext(),
                                "You clicked on Cancel",
                                Toast.LENGTH_SHORT).show();
                    }
                });
       //Showing Alert Message
        alertDialog.show();
         return true;

    }
});
0
katma

AlertDialog.show() eksik ve uzun tıkladığınızda uyarının iletişim kutusu örneğine bakın

SingleButtton.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
       //Creating alert Dialog with one Button

        AlertDialog alertDialog = new  
        AlertDialog.Builder(AlertDialogActivity.this).create();

       //Setting Dialog Title
        alertDialog.setTitle("Alert Dialog");

       //Setting Dialog Message
        alertDialog.setMessage("Welcome to Android Application");

       //Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.tick);

       //Setting OK Button
        alertDialog.setButton("OK", new 
        DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,int which) 
                    {
                       //Write your code here to execute after dialog closed
                    Toast.makeText(getApplicationContext(),"You clicked on OK", Toast.LENGTH_SHORT).show();
                    }
                });

       //Showing Alert Message
        alertDialog.show();
        return true;

    }
});


btnAlertTwoBtns.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
       //Creating alert Dialog with two Buttons

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);

       //Setting Dialog Title
        alertDialog.setTitle("Confirm Delete...");

       //Setting Dialog Message
        alertDialog.setMessage("Are you sure you want delete this?");

       //Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.delete);

       //Setting Positive "Yes" Button
        alertDialog.setPositiveButton("YES",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int which) {
                       //Write your code here to execute after dialog
                        Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
                    }
                });
       //Setting Negative "NO" Button
        alertDialog.setNegativeButton("NO",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                       //Write your code here to execute after dialog
                        Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
                        dialog.cancel();
                    }
                });

       //Showing Alert Message
        alertDialog.show();
        return true;

    }
});

btnAlertThreeBtns.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
       //Creating alert Dialog with three Buttons

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                AlertDialogActivity.this);

       //Setting Dialog Title
        alertDialog.setTitle("Save File...");

       //Setting Dialog Message
        alertDialog.setMessage("Do you want to save this file?");

       //Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.save);

       //Setting Positive Yes Button
        alertDialog.setPositiveButton("YES",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,
                            int which) {
                       //User pressed Cancel button. Write Logic Here
                        Toast.makeText(getApplicationContext(),
                                "You clicked on YES",
                                Toast.LENGTH_SHORT).show();
                    }
                });
       //Setting Negative No Button... Neutral means in between yes and cancel button
        alertDialog.setNeutralButton("NO",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,
                            int which) {
                       //User pressed No button. Write Logic Here
                        Toast.makeText(getApplicationContext(),
                                "You clicked on NO", Toast.LENGTH_SHORT)
                                .show();
                    }
                });
       //Setting Positive "Cancel" Button
        alertDialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog,
                            int which) {
                       //User pressed Cancel button. Write Logic Here
                        Toast.makeText(getApplicationContext(),
                                "You clicked on Cancel",
                                Toast.LENGTH_SHORT).show();
                    }
                });
       //Showing Alert Message
        alertDialog.show();
         return true;

    }
});
0
katma

Sadece ekle

 alertDialog.show(); 

true döndürmeden önce .

Yani,

 //Showing Alert Message
  alertDialog.show();//code to show alert message [Missed]
  return true;
0
katma

Sadece ekle

 alertDialog.show(); 

true döndürmeden önce .

Yani,

 //Showing Alert Message
  alertDialog.show();//code to show alert message [Missed]
  return true;
0
katma

AlertDialogWrapper.Builder 'ınızı AlertDialog.Builder olarak değiştirin. Ve true döndürmeden önce, alertDialog.create (); ve alertDialog.show() 'ı çağırın.

0
katma

AlertDialogWrapper.Builder 'ınızı AlertDialog.Builder olarak değiştirin. Ve true döndürmeden önce, alertDialog.create (); ve alertDialog.show() 'ı çağırın.

0
katma
You forget to do this......

 AlertDialog aD = alertDialog.create();

    try {
        aD.show();
    } catch (Exception e) {

        e.printStackTrace();
    } 
0
katma
You forget to do this......

 AlertDialog aD = alertDialog.create();

    try {
        aD.show();
    } catch (Exception e) {

        e.printStackTrace();
    } 
0
katma
//Set Reset Button
    resetBtn = (ImageButton) findViewById(R.id.resetButton);
    resetBtn.setOnLongClickListener(new Button.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialogWrapper.Builder alertDialog = new AlertDialogWrapper.Builder(MainActivity.this);
            alertDialog.setPositiveButton(getString(R.string.MAIN_MENU_RESET_ALERT_YES), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                   //Write your code here to invoke YES event
                    Toast toast = Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_YES), Toast.LENGTH_LONG);
                    toast.show();
                }
            });                alertDialog.setNegativeButton(getString(R.string.MAIN_MENU_RESET_ALERT_NO), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_NO), Toast.LENGTH_SHORT).show();
                    dialog.cancel();
                }
            });
alertDialog.show();
           //Showing Alert Message
            return true;
        }
    });

show() çağırmanız gerekir

0
katma
//Set Reset Button
    resetBtn = (ImageButton) findViewById(R.id.resetButton);
    resetBtn.setOnLongClickListener(new Button.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialogWrapper.Builder alertDialog = new AlertDialogWrapper.Builder(MainActivity.this);
            alertDialog.setPositiveButton(getString(R.string.MAIN_MENU_RESET_ALERT_YES), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                   //Write your code here to invoke YES event
                    Toast toast = Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_YES), Toast.LENGTH_LONG);
                    toast.show();
                }
            });                alertDialog.setNegativeButton(getString(R.string.MAIN_MENU_RESET_ALERT_NO), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(MainActivity.this, getString(R.string.MAIN_MENU_RESET_ALERT_RESULT_NO), Toast.LENGTH_SHORT).show();
                    dialog.cancel();
                }
            });
alertDialog.show();
           //Showing Alert Message
            return true;
        }
    });

show() çağırmanız gerekir

0
katma