Created
February 17, 2013 16:32
-
-
Save antew/4972108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
super.onCreateDialog(savedInstanceState); | |
Log.i(TAG, "onCreateDialog"); | |
LayoutInflater lf = LayoutInflater.from(getActivity()); | |
/** | |
* Inflate our custom view for this dialog, it contains | |
* two TextViews and two EditTexts, one set for the username | |
* and a second set for the password | |
*/ | |
View v = lf.inflate(R.layout.login_dialog, null); | |
username = (TextView) v.findViewById(R.id.login_username); | |
password = (TextView) v.findViewById(R.id.login_password); | |
/** | |
* Register our listener for the 'Done' key on the soft keyboard | |
*/ | |
password.setOnEditorActionListener(this); | |
username.requestFocus(); | |
final AlertDialog dialog | |
= new AlertDialog.Builder(getActivity()) | |
.setView(v) | |
.setTitle(R.string.log_in) | |
.setPositiveButton(R.string.log_in, null) | |
.setNegativeButton(R.string.cancel, null) | |
.create(); | |
/** | |
* We have to override setOnShowListener here (min API level 8) | |
* in order to validate the inputs before closing the dialog. | |
* Just overriding setPositiveButton closes the dialog | |
* automatically when the button is pressed | |
*/ | |
dialog.setOnShowListener(this); | |
/** | |
* Show the soft keyboard automatically | |
*/ | |
dialog.getWindow().setSoftInputMode( | |
LayoutParams.SOFT_INPUT_STATE_VISIBLE); | |
/** | |
* These TextWatchers are used to clear the error icons | |
* automatically once the user has remedied an error | |
*/ | |
username.addTextChangedListener(this); | |
password.addTextChangedListener(this); | |
return dialog; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment