Step 1: Create a blank activity under your java class. Give the name of the activity as RegisterActivity and check the box of fragments while creating the register activity.
Step 2: In your MainActivity declare the register button and define it by using the following code:
Button registerbutton = (Button) findViewById(R.id.button3);
Here button3 is the id of the register button.
Step 3: in the fragment_register.xml file give the fields that you want in your register screen by using EditText and TextView. This can be done as follows:
<TextView
android:layout_width=“wrap_content”
android:text=“Email”
android:layout_height=“wrap_content” />
<EditText
android:id=“@+id/etEmail”
android:layout_width=“match_parent”
android:layout_marginBottom=“10dp”
android:layout_height=“wrap_content” /> <TextView
android:layout_width=“wrap_content”
android:text=“Password”
android:layout_height=“wrap_content” />
<EditText
android:id=“@+id/etPassword”
android:layout_width=“match_parent”
android:layout_marginBottom=“10dp”
android:layout_height=“wrap_content” />
TextView gives the name of the field that you want to display. And the EditText is where you can enter your data , which here is the email and password.
Like this many other fields can also be added to your register screens.
To add a functionality of registering n clicking the button add the below code in your java file.
registerbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final Intent registerIntent = new Intent().setClass(LandingPageActivity.this, RegisterActivity.class);
startActivity(registerIntent);
}
});
The register button is available on our MainActivity page , which is the landing page here. So when the register button is pressed the setOnClickListener event is called and the register screen appears and you can enter the user’s details there and press the register button at the bottom of the screen to register.
Your screen will look like this: