Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Diffrent types of signUp pages in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 298
    Comment on it

    Signup tutorials for the beginners. In this tutorial you can see different types of signup pages in which date of birth is included , Signup using Facebook and other options as well for android. You can add this code in you application to get the signup functionality in your app. I will show you one of the Signup form below to show the validation functionality. You will also find the HttpPost and HttpGet method to use signup services you just have to set URL and call whatever service you want.

    Here is the Activity Class

    public class SignUpOne extends Activity implements OnClickListener{
    private Button signUpButton;
    private EditText dateOfBirthEditText, usernameEditText, passwordEditText,retypePassword,emailEditText,phoneEditText;
    private Calendar cal;
    private int day;
    private int month;
    private int year;
    private DatePickerDialog alert;
    private ArrayList<NameValuePair> nameValuePair;
    //to display type of seprator in date
    private String dateSeprater="/";
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signup&#95;one);
        cal = Calendar.getInstance();
        day = cal.get(Calendar.DAY&#95;OF&#95;MONTH);
        month = cal.get(Calendar.MONTH);
        year = cal.get(Calendar.YEAR);
        usernameEditText = (EditText) findViewById(R.id.username&#95;editText);
        passwordEditText = (EditText) findViewById(R.id.password&#95;editText);
        retypePassword = (EditText) findViewById(R.id.retype&#95;password&#95;editText);
        emailEditText = (EditText) findViewById(R.id.email&#95;editText);
        phoneEditText = (EditText) findViewById(R.id.phone&#95;editText);
        dateOfBirthEditText = (EditText) findViewById(R.id.date&#95;of&#95;birth&#95;editText);
        signUpButton = (Button) findViewById(R.id.sign&#95;up&#95;button);
        signUpButton.setOnClickListener(this);
        // creating date  picker in alert view
        alert =new DatePickerDialog(this,datePickerListener,year, month, day);      
        dateOfBirthEditText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //to display date time picker
                alert.show();
            }
    
        });
    }
    
    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
    
        if (view == signUpButton) {
            // checking validation of all edittext at the time of signup
            if(!usernameEditText.getText().toString().isEmpty()&&!passwordEditText.getText().toString().isEmpty()&&!emailEditText.getText().toString().isEmpty()&&!!emailEditText.getText().toString().contains("@"))
            {//calling asynctask if all fields are validated
                new SignUpUserPost().execute();
                new SignUpUserGet().execute();
                //Toast.makeText(SignUpOne.this, "success", Toast.LENGTH&#95;LONG).show();                  
            }
            if(dateOfBirthEditText.getText().toString().isEmpty()){
                dateOfBirthEditText.setError(getString(R.string.empty&#95;filed));
                dateOfBirthEditText.requestFocus();
            }
            if(!emailEditText.getText().toString().contains("@")||!emailEditText.getText().toString().contains("."))
            {
                emailEditText.setError(getString(R.string.invalid&#95;email));
                emailEditText.requestFocus();
            }
            if(emailEditText.getText().toString().isEmpty()){
                emailEditText.setError(getString(R.string.empty&#95;filed));
                emailEditText.requestFocus();
            }
            if(passwordEditText.length()<6){
                passwordEditText.setError(getString(R.string.password&#95;length));
                passwordEditText.requestFocus();
            }
            if(!passwordEditText.getText().toString().equals(retypePassword.getText().toString())){
                retypePassword.setError(getString(R.string.password&#95;unmatch));  
                retypePassword.requestFocus();
            }
            if(retypePassword.getText().toString().isEmpty()){
                retypePassword.setError(getString(R.string.empty&#95;filed));
                retypePassword.requestFocus();
            }
            if(passwordEditText.getText().toString().isEmpty()){
                passwordEditText.setError(getString(R.string.empty&#95;filed));
                passwordEditText.requestFocus();
            }
            if(usernameEditText.getText().toString().isEmpty()){
                usernameEditText.setError(getString(R.string.empty&#95;filed));
                usernameEditText.requestFocus();
            }   
        }
    
    }
    
    // this method is to create alert date picker 
    private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int selectedYear,
                int selectedMonth, int selectedDay) {
            dateOfBirthEditText.setText(selectedDay + dateSeprater + (selectedMonth + 1) + dateSeprater
                    + selectedYear);        
        }
    };
    
    //Asynctask to call signup using post service
    private class SignUpUserPost extends AsyncTask<String, Void, String> {
        ProgressDialog dialog;
    
        @Override
        protected void onPreExecute() {
            dialog = new ProgressDialog(SignUpOne.this);
            dialog.setCancelable(false);
            dialog.setMessage(SignUpOne.this.getResources().getString(R.string.please&#95;wait));
            dialog.show();
        }
    
        @Override
        protected String doInBackground(String... httpMethod) {
            // TODO Auto-generated method stub
            try {
                nameValuePair = new ArrayList<NameValuePair>(2);
                nameValuePair.add(new BasicNameValuePair("Username", usernameEditText.getText().toString()));
                nameValuePair.add(new BasicNameValuePair("Password", passwordEditText.getText().toString()));
                nameValuePair.add(new BasicNameValuePair("email", emailEditText.getText().toString()));
                if(!phoneEditText.getText().toString().isEmpty()){
                    nameValuePair.add(new BasicNameValuePair("phoneNumber", phoneEditText.getText().toString()));
                }
                nameValuePair.add(new BasicNameValuePair("DateOfBirth", dateOfBirthEditText.getText().toString()));
                return WebServiceConnection.postData(ServerUrls.SIGNUP, nameValuePair);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(String result) {
    
            dialog.dismiss();
            XMLParser parser = new XMLParser();
            Document doc = parser.getDomElement(result);
            NodeList nl = doc.getElementsByTagName(Constants.SIGNUP&#95;RESPONSE);
            Element element = (Element) nl.item(0);
        }
    }
    
    //Asynctask to call signup using get service
    private class SignUpUserGet extends AsyncTask<String, Void, String> {
        ProgressDialog dialog;
    
        @Override
        protected void onPreExecute() {
            dialog = new ProgressDialog(SignUpOne.this);
            dialog.setCancelable(false);
            dialog.setMessage(SignUpOne.this.getResources().getString(R.string.please&#95;wait));
            dialog.show();
        }
    
        @Override
        protected String doInBackground(String... httpMethod) {
            // TODO Auto-generated method stub
            try {String url;
            if(!phoneEditText.getText().toString().isEmpty()){
                url =ServerUrls.SIGNUP+"Username"+usernameEditText.getText().toString()+"Password"+passwordEditText.getText().toString()+"email"+emailEditText.getText().toString()+"phoneNumber"+phoneEditText.getText().toString()+"DateOfBirth"+dateOfBirthEditText.getText().toString() ;
            }
            else{url =ServerUrls.SIGNUP+"Username"+usernameEditText.getText().toString()+"Password"+passwordEditText.getText().toString()+"email"+emailEditText.getText().toString()+"DateOfBirth"+dateOfBirthEditText.getText().toString() ;
            }
            return WebServiceConnection.GetData(url);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(String result) {
            dialog.dismiss();
            XMLParser parser = new XMLParser();
            Document doc = parser.getDomElement(result);
            NodeList nl = doc.getElementsByTagName(Constants.SIGNUP&#95;RESPONSE);
            Element element = (Element) nl.item(0);
        }
    }
    
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        nameValuePair=null;
        alert=null;
        super.onDestroy();
    }
    

    }

    Hope you will find it helpful.. :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: