I have an alert dialog, that I have 2 text fields and then a Positive and Negative button.
I was trying to set the nextFocusDown on the final text field to ALWAYS be the positive button.
The positive and negative buttons are layed out beside each other below the second text field and if the cursor for user input was over the left button the nextfocus would move to the left button, if it was over the right button it would move to the right button.
So I use my alert builder to CREATE my alert Dialog and then attempted to call
myAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
and then set the ExitText fields nextFocusDownId to that button’s ID.
and do this before I show the Alert to the user, so I don’t have the slightest chance of any racing conditions.
Alas, the ad.getButton returns NULL every single time. When I move these lines of code to after the ad.show() call, everything works perfectly.
So I guess the question I have is, can someone explain this to me. I would think once I have SET THE POSITIVE BUTTON and created the AlertDialog that the view should exist but not be visible… obviously this is not the case, so does nothing that is a DisplayWidget get create until the view is actually shown as a general rule of thumb? When views are inflated I am able to find objects within them before I show them. So what is the general rule of thumb regarding this?
I think your final statements/questions are on the right track. The call to
show()on the dialog inflates and shows the view. So in sort of makes sense that you cannot interact with the view in code until the dialog is shown. I don’t see there being much of a race condition if your code to manipulate the dialog comes directly after callingshow().Specifically, here is what the javadoc says:
So the dialog is not “started” until
show()is called.