Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1.  public void register() {
  2.         //create builder
  3.         android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
  4.         //set title
  5.         builder.setTitle(R.string.register);
  6.  
  7.         //inflate view from layout ->custom layout,null,false as defualt values
  8.         View viewInflated = LayoutInflater.from(context).inflate(R.layout.dlg_new_task, null, true);
  9.  
  10.         final EditText txtUser = (EditText)viewInflated.findViewById(R.id.txtUserName);
  11.         final EditText txtPass = (EditText)viewInflated.findViewById(R.id.txtPassword);
  12.         final EditText txtPass2 = (EditText)viewInflated.findViewById(R.id.txtPassword2);
  13.  
  14.         builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  15.             @Override
  16.             public void onClick(DialogInterface dialogInterface, int i) {
  17.                 dialogInterface.dismiss();
  18.             }
  19.         });
  20.  
  21.  
  22.  
  23.         final utlShared myShared = new utlShared(context);
  24.         builder.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
  25.  
  26.             @Override
  27.             public void onClick(DialogInterface dialogInterface, int i) {
  28.                 dialogInterface.dismiss();
  29.  
  30.                 String pass1=txtPass.getText().toString();
  31.                 String pass2=txtPass2.getText().toString();
  32.  
  33.                 if (!pass1.equals(pass2)) {
  34.                     Toast.makeText(context, R.string.errorSamepass, Toast.LENGTH_LONG).show();
  35.                     register();
  36.                     return;
  37.                 }
  38.  
  39.                 utlShared myShared = new utlShared(context);
  40.                 String userName=txtUser.getText().toString();
  41.  
  42.                 //check if user exists
  43.                 if (myShared.checkUser(userName)) {
  44.                     Toast.makeText(context, R.string.userExixst, Toast.LENGTH_SHORT).show();
  45.                     register();
  46.                     return;
  47.                 }
  48.                 //running the method of add user
  49.                 myShared.addUser(userName,pass1);
  50.  
  51.  
  52.  
  53.             }
  54.         });
  55.  
  56.         //display our inflated view in screen
  57.         builder.setView(viewInflated);
  58.         //show the dialog
  59.         builder.show();
  60.  
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement