How do i close the alert dialog that displays custom view
Posted
by
Asdfg
on Stack Overflow
See other posts from Stack Overflow
or by Asdfg
Published on 2012-03-20T05:24:29Z
Indexed on
2012/03/20
5:29 UTC
Read the original article
Hit count: 346
I have an activity named MainActivity
which has a button. On click of that button i am displaying an AlertDialog which contains a custom view named ChildWindow.xml
. That custom view has multiple textboxes and a OK button. On click of the OK button, i am calling a method of MainActivity. I am able to access the ChildWindow here as
view.getRootView().findViewById(R.id.txtFirstName);
Once the user clicks on the OK button, i have to close the alert dialog which i am able to do as view.getRootView().setVisibility(View.GONE);
My problem is even though i have closed the the ChildWindow in the above statement, i am able to get reference to the textbox in the next line which means AlertDialog is closed but child window is still there. This is how the OK button click looks like:
This works as expected:
EditText tb = (EditText) view.getRootView().findViewById(R.id.txtFirstName);
Toast toast = Toast.makeText(getApplicationContext(), tb.getText(), Toast.LENGTH_LONG);
toast.show();
view.getRootView().setVisibility(View.GONE);
This should not work as i am closing the alert dialog and then getting the reference of the textbox but this works too.
view.getRootView().setVisibility(View.GONE);
EditText tb = (EditText) view.getRootView().findViewById(R.id.txtFirstName);
Toast toast = Toast.makeText(getApplicationContext(), tb.getText(), Toast.LENGTH_LONG);
toast.show();
I think i am closing the alert dialog but i am not destroying it from the memory. Can someone point me out what am i missing here?
© Stack Overflow or respective owner