dialog - The specified child already has a parent. You must call removeView() on the child's parent first

The problem is on this line: alert.setView(input); You added input View that have already parent. Create new input instance.


according to this post, add this check to remove input from it's parent and readd it:

if(input.getParent()!=null)
        ((ViewGroup)input.getParent()).removeView(input); // <- fix
    alert.addView(input);

Put following line

 final AlertDialog alertd = alert.create();

After

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

Tags:

Java

Android