Advertisement
EylonYizhack

Register Activity_Eylon

Mar 9th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. //Register Activity
  2. //________________________________________________________
  3. package com.example.eylonyizhack.myapp63;
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.content.SharedPreferences;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13.  
  14. public class RegisterActivity extends Activity {
  15. EditText editFirstName, editFirstPass,editSecondPass;
  16. //_________________________________________________________________________
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState)
  19.     {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_register);
  22.         setPointer();
  23.     }
  24. //__________________________________________________________________________
  25.     public void setPointer()
  26.     {EditText editFirstName=(EditText)findViewById(R.id.ETFirstName);
  27.      EditText editFirstPass=(EditText)findViewById(R.id.ETFirstPassword);
  28.      EditText editSecondPass=(EditText)findViewById(R.id.ETSecondPassword);}
  29.  
  30.     //Return to the main menu/////////////////////////
  31.     public void btnCancel(View view)
  32.     {Intent iMain = new Intent(this,MainActivity.class);
  33.         this.startActivity(iMain);}
  34.     //////////////////////////////////////////////////
  35.  
  36.     //________________REGISTER BUTTON____________________//
  37.     public void btnRegisterNow(View vie)
  38.     {
  39.         SharedPreferences pref=getApplicationContext().getSharedPreferences("myPref",MODE_PRIVATE);
  40.         //declartion of editor to edit shared preferances
  41.         SharedPreferences.Editor editor=pref.edit();
  42.         //insert into string value from EditText
  43.         String userName=editFirstName.getText().toString();
  44.         String password1=editFirstPass.getText().toString();
  45.         String password2=editSecondPass.getText().toString();
  46.        // String userDB=pref.getString("userRegister", "ErrorUser");
  47.  
  48.         if(userName.equals("")||password1.equals("")){
  49.             Toast.makeText(this, "Please type username and password", Toast.LENGTH_LONG).show();
  50.             return;
  51.         }
  52.       /*  else if(userName.equals(userDB)) {
  53.             Toast.makeText(this, "The username is already exist, please type another username", Toast.LENGTH_LONG).show();
  54.             return;
  55.         }*/
  56.         else if(!password1.equals(password2)){
  57.             Toast.makeText(this, "You must type same password", Toast.LENGTH_LONG).show();
  58.             return;
  59.         }
  60.         //create key "user" with value of userName, if key exists, it will be overwritten
  61.         editor.putString("userReg", userName);
  62.         editor.putString("passReg", password1);
  63.  
  64.         //commit the changes
  65.         editor.commit();
  66.  
  67.         //Finally done with the register part and return to the main menu
  68.         Intent seccsesReg = new Intent(this, MainActivity.class);
  69.         Toast.makeText(this,"Registering..",Toast.LENGTH_LONG).show();
  70.         this.startActivity(seccsesReg);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement