Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.tiketsaya;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.Toast;
- import com.google.firebase.database.DataSnapshot;
- import com.google.firebase.database.DatabaseError;
- import com.google.firebase.database.DatabaseReference;
- import com.google.firebase.database.FirebaseDatabase;
- import com.google.firebase.database.ValueEventListener;
- import androidx.annotation.NonNull;
- import androidx.appcompat.app.AppCompatActivity;
- public class RegisterOneActivity extends AppCompatActivity {
- LinearLayout btnBack;
- Button btnContinue;
- EditText username,password,email_address;
- DatabaseReference reference;
- String USERNAME_KEY = "usernamekey";
- String username_key = "";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register_one);
- username = findViewById(R.id.username);
- password = findViewById(R.id.password);
- email_address = findViewById(R.id.email_address);
- btnBack = findViewById(R.id.btnBack);
- btnBack.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onBackPressed();
- }
- });
- btnContinue = findViewById(R.id.btnContinue);
- btnContinue.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //save to local
- SharedPreferences sharedPreferences = getSharedPreferences(USERNAME_KEY, MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPreferences.edit();
- editor.putString(username_key, username.getText().toString());
- editor.apply();
- //Toast.makeText(getApplicationContext(), "Username: " + username.getText().toString(), Toast.LENGTH_SHORT).show();
- //save to db
- reference = FirebaseDatabase.getInstance().getReference().child(username.getText().toString());
- reference.addListenerForSingleValueEvent(new ValueEventListener() {
- @Override
- public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
- dataSnapshot.getRef().child("username").setValue(username.getText().toString());
- dataSnapshot.getRef().child("password").setValue(password.getText().toString());
- dataSnapshot.getRef().child("email_address").setValue(email_address.getText().toString());
- dataSnapshot.getRef().child("user_balance").setValue(800);
- }
- @Override
- public void onCancelled(@NonNull DatabaseError databaseError) {
- }
- });
- Intent nextRegist = new Intent(RegisterOneActivity.this, RegisterTwoActivity.class);
- startActivity(nextRegist);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement