Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void register() {
- //create builder
- android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
- //set title
- builder.setTitle(R.string.register);
- //inflate view from layout ->custom layout,null,false as defualt values
- View viewInflated = LayoutInflater.from(context).inflate(R.layout.dlg_new_task, null, true);
- final EditText txtUser = (EditText)viewInflated.findViewById(R.id.txtUserName);
- final EditText txtPass = (EditText)viewInflated.findViewById(R.id.txtPassword);
- final EditText txtPass2 = (EditText)viewInflated.findViewById(R.id.txtPassword2);
- builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
- final utlShared myShared = new utlShared(context);
- builder.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- String pass1=txtPass.getText().toString();
- String pass2=txtPass2.getText().toString();
- if (!pass1.equals(pass2)) {
- Toast.makeText(context, R.string.errorSamepass, Toast.LENGTH_LONG).show();
- register();
- return;
- }
- utlShared myShared = new utlShared(context);
- String userName=txtUser.getText().toString();
- //check if user exists
- if (myShared.checkUser(userName)) {
- Toast.makeText(context, R.string.userExixst, Toast.LENGTH_SHORT).show();
- register();
- return;
- }
- //running the method of add user
- myShared.addUser(userName,pass1);
- }
- });
- //display our inflated view in screen
- builder.setView(viewInflated);
- //show the dialog
- builder.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement