Lompat ke konten Lompat ke sidebar Lompat ke footer

Widget HTML #1

Cara Membuat Sign Up Register Java Android Studio Simple Programmatically

 


Syarat :

Sudah Setting Tools Firebase di android studionya

 

Javanya 

package com.ranairu.creation;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

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

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class Register extends AppCompatActivity {
private FirebaseAuth mAuth;
private EditText email, password;
private Button btnRegister;
private TextView textLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ini_register);
mAuth = FirebaseAuth.getInstance();
email = findViewById(R.id.register_email);
password = findViewById(R.id.register_password);
btnRegister = findViewById(R.id.register);
textLogin = findViewById(R.id.text_login);

btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Register();
}
});

textLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Register.this, Login.class));
}
});

}

private void Register()
{
String user = email.getText().toString().trim();
String pass = password.getText().toString().trim();
if(user.isEmpty())
{
email.setError("Email can not be empty");
}
if(pass.isEmpty())
{
password.setError("Password can not be empty");
}
else
{
mAuth.createUserWithEmailAndPassword(user, pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(Register.this, "User registered successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Register.this, MainActivity.class));
}
else
{
Toast.makeText(Register.this, "Registration Failed"+task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}

}
});
}
}
}

XML nya

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".Register"
android:layout_margin="10dp">

<TextView
android:id="@+id/text_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register Here"
android:textSize="20dp"
android:layout_marginBottom="20dp"/>

<EditText
android:id="@+id/register_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="email"
android:layout_below="@+id/text_register"
android:layout_marginBottom="20dp"
/>

<EditText
android:id="@+id/register_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:layout_below="@+id/register_email"
android:layout_marginBottom="20dp"
/>

<Button
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register_password"
android:text="Register"
android:layout_marginBottom="20dp"/>

<TextView
android:id="@+id/text_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register"
android:text="Existing User Login"
android:layout_marginBottom="20dp"
android:textAlignment="center"/>

</RelativeLayout>



Posting Komentar untuk "Cara Membuat Sign Up Register Java Android Studio Simple Programmatically"