Registration Form In Android With Source Code



Create Registration Form In Android

Here I have created a registration form in android. In my registration form i have used  edit text , check box , radio button , toggle button, switch button , Intent class etc. Therefor below example will clearly described you to make Registration form.

1. Registration Form XML (Design) File Code


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".RegistrationForm"

    android:orientation="vertical">


    <ScrollView

        android:layout_width="match_parent"

        android:layout_height="match_parent">

    <TableLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent">

        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:gravity="center">

            <TextView

                android:id="@+id/lblName"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:textSize="25dp"

                android:textColor="@android:color/black"

                android:text="@string/RegistrationLable" />

        </TableRow>


        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:weightSum="10"

            android:layout_marginTop="20dp">

            <EditText

                android:id="@+id/txtName"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="10"

                android:ems="10"

                android:hint="Name"

                android:inputType="textPersonName"

                android:text="" />

        </TableRow>


        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:weightSum="2"

            android:layout_marginTop="20dp"

            android:orientation="horizontal">

            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="0.8">

                <TextView

                    android:id="@+id/lblGender"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:text="Gender"/>

            </LinearLayout>


            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="1.2">

                <RadioGroup

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:id="@+id/rgGender"

                    android:orientation="horizontal">

                    <RadioButton

                        android:id="@+id/rbMale"

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:text="Male"

                        />

                    <RadioButton

                        android:id="@+id/rbFemale"

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:text="Female" />

                </RadioGroup>

            </LinearLayout>

        </TableRow>


        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:weightSum="2"

            android:layout_marginTop="20dp"

            android:orientation="horizontal">

            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="0.8">

                <TextView

                    android:id="@+id/lblHobby"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:text="Hobby"/>

            </LinearLayout>


            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="1.2">

                <CheckBox

                    android:id="@+id/checkDance"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_weight="1"

                    android:text="Dance" />

                <CheckBox

                    android:id="@+id/checkRead"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_weight="1"

                    android:text="Read" />

                <CheckBox

                    android:id="@+id/checkGame"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_weight="1"

                    android:text="Game" />

            </LinearLayout>

        </TableRow>


        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:weightSum="2"

            android:layout_marginTop="20dp"

            android:orientation="horizontal">

            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="0.8">

                <TextView

                    android:id="@+id/lblMarried"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:text="Are you married ?"/>

            </LinearLayout>


            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="0.5">

                <ToggleButton

                    android:id="@+id/toggleBtnMarried"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_weight="1"

                    android:text="ToggleButton"

                    android:textOff="No"

                    android:textOn="Yes" />

            </LinearLayout>

        </TableRow>


        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:weightSum="2"

            android:layout_marginTop="20dp"

            android:orientation="horizontal">

            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="0.8">

                <TextView

                    android:id="@+id/lblGraduate"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:text="Are you graduate ?"/>

            </LinearLayout>


            <LinearLayout

                android:layout_width="0dp"

                android:layout_height="match_parent"

                android:layout_weight="0.3">

                <Switch

                    android:id="@+id/switchGraduate"

                    android:layout_width="wrap_content"

                    android:layout_height="15dp"

                    android:layout_weight="1"

                    android:text=""

                    android:textOff="No"

                    android:textOn="Yes" />

            </LinearLayout>

        </TableRow>


        <TableRow

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:gravity="center"

            android:layout_marginTop="20dp">

            <Button

                android:id="@+id/btnSubmit"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Submit" />

        </TableRow>


    </TableLayout>

    </ScrollView>

</LinearLayout>



2. Registration Form .JAVA File Code


package com.spt.androidpractical;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.Toast;
import android.widget.ToggleButton;

public class RegistrationForm extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration_form);

// Declare

        final EditText txtName;
        final RadioGroup rgGender;
        final CheckBox checkDance, checkRead, checkGame;
        final ToggleButton toggleBtnMarried;
        final Switch switchGraduate;
        Button btnSubmit;

// Get control using id

        txtName = findViewById(R.id.txtName);
        rgGender = findViewById(R.id.rgGender);
        checkDance = findViewById(R.id.checkDance);
        checkRead = findViewById(R.id.checkRead);
        checkGame = findViewById(R.id.checkGame);
        toggleBtnMarried = findViewById(R.id.toggleBtnMarried);
        switchGraduate = findViewById(R.id.switchGraduate);
        btnSubmit = findViewById(R.id.btnSubmit);


        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String tempName,tempGender,tempHobbay="",tempMarried,tempGraduate;


//  Get EditText value

                tempName = txtName.getText().toString();


// Get radio button value

                try {
                    tempGender = ((RadioButton) findViewById(rgGender.getCheckedRadioButtonId())).getText().toString();
                }
                catch (Exception e)
                {
                    tempGender = "";
                }

// Get CheckBox value

                if(checkDance.isChecked())
                {
                    tempHobbay = checkDance.getText().toString();
                }

                if(checkRead.isChecked())
                {
                    tempHobbay = tempHobbay + " " + checkRead.getText().toString();
                }

                if(checkGame.isChecked())
                {
                    tempHobbay = tempHobbay + " " + checkGame.getText().toString();
                }

// Get ToggleButton value

                tempMarried = toggleBtnMarried.getText().toString();

   // Get Switch value                 if(switchGraduate.isChecked())
                {
                    tempGraduate = "Yes";
                }
                else {

                    tempGraduate = "No";
                }

// Create Intent variable to pass data & open second activity

                Intent i = new Intent(getApplicationContext(),RegistrationData.class);

                i.putExtra("Name",tempName);
                i.putExtra("Gender",tempGender);
                i.putExtra("Hobby",tempHobbay);
                i.putExtra("Married",tempMarried);
                i.putExtra("Graduate",tempGraduate);

                startActivity(i);

            }
        });

    }
}




Registration Form Output

Registration Form In Android With Source Code

3. Registration Data XML (Design) File Code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RegistrationForm"
    android:orientation="vertical">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center">

                <TextView
                    android:id="@+id/lblName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="25dp"
                    android:textColor="@android:color/black"
                    android:text="@string/RegistrationDataLable" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="2"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8">

                    <TextView
                        android:id="@+id/lblNameData"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Name"

                        />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2">

                    <TextView
                        android:id="@+id/txtNameData"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="" />

                </LinearLayout>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="2"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8">

                    <TextView
                        android:id="@+id/lblGender"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Gender"/>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2">

                    <TextView
                        android:id="@+id/txtGender"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="" />


                </LinearLayout>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="2"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8">

                    <TextView
                        android:id="@+id/lblHobby"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Hobby"/>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2">

                    <TextView
                        android:id="@+id/txtHobby"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="" />


                </LinearLayout>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="2"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8">

                    <TextView
                        android:id="@+id/lblMarried"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Married"/>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2">

                    <TextView
                        android:id="@+id/txtMarried"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="" />


                </LinearLayout>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="2"
                android:layout_marginTop="20dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8">

                    <TextView
                        android:id="@+id/lblGraduate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                       android:text="Graduate"/>
   
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2">

                    <TextView
                        android:id="@+id/txtGraduate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="" />

                </LinearLayout>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_marginTop="20dp">

                <Button
                    android:id="@+id/btnBack"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Back" />
            </TableRow>

        </TableLayout>

    </ScrollView>

</LinearLayout>

4. Registration Data .JAVA File Code

package com.spt.androidpractical;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class RegistrationData extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration_data);

// Declare

        TextView txtNameData, txtGender, txtHobby, txtMarried, txtGraduate;
        Button btnBack = findViewById(R.id.btnBack);

// Get control using id

        txtNameData = findViewById(R.id.txtNameData);
        txtGender = findViewById(R.id.txtGender);
        txtHobby = findViewById(R.id.txtHobby);
        txtMarried = findViewById(R.id.txtMarried);
        txtGraduate = findViewById(R.id.txtGraduate);

// Get first activity intent

        Intent i = getIntent();

// Get intent value

        txtNameData.setText(i.getStringExtra("Name"));
        txtGender.setText(i.getStringExtra("Gender"));
        txtHobby.setText(i.getStringExtra("Hobby"));
        txtMarried.setText(i.getStringExtra("Married"));
        txtGraduate.setText(i.getStringExtra("Graduate"));

// Back button click event

        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent s = new Intent(getApplicationContext(),RegistrationForm.class);
                startActivity(s);
            }
        });
    }
}


After Registration Output

Registration Form In Android With Source Code

Comments