Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Register Activity
- //________________________________________________________
- package com.example.eylonyizhack.myapp63;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- public class RegisterActivity extends Activity {
- EditText editFirstName, editFirstPass,editSecondPass;
- //_________________________________________________________________________
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- //__________________________________________________________________________
- public void setPointer()
- {EditText editFirstName=(EditText)findViewById(R.id.ETFirstName);
- EditText editFirstPass=(EditText)findViewById(R.id.ETFirstPassword);
- EditText editSecondPass=(EditText)findViewById(R.id.ETSecondPassword);}
- //Return to the main menu/////////////////////////
- public void btnCancel(View view)
- {Intent iMain = new Intent(this,MainActivity.class);
- this.startActivity(iMain);}
- //////////////////////////////////////////////////
- //________________REGISTER BUTTON____________________//
- public void btnRegisterNow(View vie)
- {
- SharedPreferences pref=getApplicationContext().getSharedPreferences("myPref",MODE_PRIVATE);
- //declartion of editor to edit shared preferances
- SharedPreferences.Editor editor=pref.edit();
- //insert into string value from EditText
- String userName=editFirstName.getText().toString();
- String password1=editFirstPass.getText().toString();
- String password2=editSecondPass.getText().toString();
- // String userDB=pref.getString("userRegister", "ErrorUser");
- if(userName.equals("")||password1.equals("")){
- Toast.makeText(this, "Please type username and password", Toast.LENGTH_LONG).show();
- return;
- }
- /* else if(userName.equals(userDB)) {
- Toast.makeText(this, "The username is already exist, please type another username", Toast.LENGTH_LONG).show();
- return;
- }*/
- else if(!password1.equals(password2)){
- Toast.makeText(this, "You must type same password", Toast.LENGTH_LONG).show();
- return;
- }
- //create key "user" with value of userName, if key exists, it will be overwritten
- editor.putString("userReg", userName);
- editor.putString("passReg", password1);
- //commit the changes
- editor.commit();
- //Finally done with the register part and return to the main menu
- Intent seccsesReg = new Intent(this, MainActivity.class);
- Toast.makeText(this,"Registering..",Toast.LENGTH_LONG).show();
- this.startActivity(seccsesReg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement