SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.ecommerce;
  2.  
  3.    import androidx.annotation.NonNull;
  4.   import androidx.appcompat.app.AppCompatActivity;
  5.  
  6.    import android.app.ProgressDialog;
  7.    import android.content.Intent;
  8.   import android.os.Bundle;
  9.   import android.text.TextUtils;
  10.  import android.view.View;
  11.   import android.widget.*;
  12.  
  13.  import com.google.android.gms.tasks.OnCompleteListener;
  14.  import com.google.android.gms.tasks.Task;
  15. import com.google.firebase.database.DataSnapshot;
  16.  import com.google.firebase.database.DatabaseError;
  17. import com.google.firebase.database.DatabaseReference;
  18.  import com.google.firebase.database.FirebaseDatabase;
  19.  import com.google.firebase.database.ValueEventListener;
  20.  
  21.    import java.util.HashMap;
  22.  
  23.   public class register extends AppCompatActivity {
  24.  
  25.      EditText inputname, password, Phone ;
  26.     Button createaccount;
  27.     ProgressDialog loadingbar;
  28.     FirebaseDatabase database;
  29.     DatabaseReference ref;
  30.       User user ;
  31.  
  32.  
  33.  
  34.   @Override
  35.    protected void onCreate(Bundle savedInstanceState) {
  36.       super.onCreate(savedInstanceState);
  37.       setContentView(R.layout.activity_register);
  38.  
  39.       inputname = findViewById(R.id.username);
  40.       password = findViewById(R.id.reg_password);
  41.       Phone = findViewById(R.id.reg_phone_number);
  42.       createaccount = findViewById(R.id.create_account);
  43.       // loadingbar=new ProgressDialog(this);
  44.        ref = database.getReference("User");
  45.       user = new User();
  46.  
  47. }
  48.  
  49. public void getValues(){
  50.     user.setName(inputname.getText().toString());
  51.     user.setPhone(Phone.getText().toString());
  52.    user.setPassword(password.getText().toString());
  53. }
  54.  public void btn  (View view)
  55. {
  56.    ref.addListenerForSingleValueEvent(new ValueEventListener() {
  57.     @Override
  58.     public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  59.  
  60.         getValues();
  61.         ref.child("user02").setValue(user);
  62.         Toast.makeText(register.this,"Data Inserted",Toast.LENGTH_LONG).show();
  63.     }
  64.  
  65.     @Override
  66.     public void onCancelled(@NonNull DatabaseError databaseError) {
  67.  
  68.     }
  69. });
  70.      
  71. }
  72.  
  73.  
  74.  User class :
  75.  
  76. package com.example.ecommerce;
  77.  
  78. public class User {
  79.  
  80.  
  81.   private String Name;
  82.   private String Phone;
  83.   private String Password;
  84.  
  85. public User() {
  86.  
  87. }
  88.  
  89. public User(String name, String phone, String password) {
  90.     Name = name;
  91.     Phone = phone;
  92.     Password = password;
  93. }
  94.  
  95.  
  96.  
  97. public String getName() {
  98.     return Name;
  99. }
  100.  
  101. public void setName(String name) {
  102.     Name = name;
  103. }
  104.  
  105. public String getPhone() {
  106.     return Phone;
  107. }
  108.  
  109. public void setPhone(String phone) {
  110.     Phone = phone;
  111. }
  112.  
  113. public String getPassword() {
  114.     return Password;
  115. }
  116.  
  117. public void setPassword(String password) {
  118.     Password = password;
  119. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top