Home » Java » java – Alert dialog doesn't show anything-Exceptionshub

java – Alert dialog doesn't show anything-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have an Alert Dialog and when I press the button to show what I chose, it shows nothing, only the black faded screen like something has to show.

There is my code:

final AlertDialog.Builder raspunsgresit = new AlertDialog.Builder(Intrebarea644.this);
LayoutInflater factory = LayoutInflater.from(Intrebarea644.this);
final View view = factory.inflate(R.layout.raspuns644, null);
raspunsgresit.setView(view);
if(view.getParent()!=null)
   ((ViewGroup)view.getParent()).removeView(view);
raspunsgresit.setPositiveButton("", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dlg, int sumthin) {
            }
    });
How to&Answers:

It’s just the AlertDialog.Builder. You need to create() the AlertDialog then show() it.
So, your code will look like :

final AlertDialog.Builder raspunsgresit = new AlertDialog.Builder(Intrebarea644.this);
LayoutInflater factory = LayoutInflater.from(Intrebarea644.this);
final View view = factory.inflate(R.layout.raspuns644, null);
raspunsgresit.setView(view);
if(view.getParent()!=null)
 ((ViewGroup)view.getParent()).removeView(view);
raspunsgresit.setPositiveButton("", new DialogInterface.OnClickListener(){
 public void onClick(DialogInterface dlg, int sumthin){
 }
});
raspunsgresit.create().show();