So, I have a button that displays a warning dialog when clicked. I am creating a view for the warning dialog in the onCreate method of my activity. The code for this is here:
LayoutInflater factory = LayoutInflater.from(this); view = factory.inflate(R.layout.grade_result, null);
When I click the button for the first time, the dialog box displays the way I want it, but when I click it the second time, it throws this exception
11-28 00: 35: 58.066: E / AndroidRuntime (30348): caused by: java.lang.IllegalStateException: the specified child already has a parent. You must first call removeView () on the parent parent.
My code for the method that displays AlertDialog when the button is pressed is here:
public void details(View v){ final AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setView(view); alert.setMessage("Details About Your Grades") .setCancelable(false) .setPositiveButton("Continue", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id){ dialog.cancel(); } }); alert.show();
Any help would be appreciated! Thanks!
source share