Advertisement
iNoobAvicena

Main

Nov 18th, 2021
526
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.tugassqlfirebase;
  2.  
  3. import androidx.annotation.Nullable;
  4. import androidx.appcompat.app.AppCompatActivity;
  5.  
  6. import android.content.Intent;
  7. import android.database.Cursor;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.TextView;
  12.  
  13. import com.google.firebase.auth.FirebaseAuth;
  14.  
  15. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  16.  
  17.     TextView _ID, _Name, _Username, _Age, _Status;
  18.     Button _Update, _Exit;
  19.     DatabaseHelper _DB;
  20.  
  21.     String fullname, username, age, status;
  22.  
  23.     @Override
  24.     protected void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.activity_main);
  27.         _ID = findViewById(R.id.idUser);
  28.         _Name = findViewById(R.id.Fullname);
  29.         _Username = findViewById(R.id.Username);
  30.         _Age = findViewById(R.id.Usia);
  31.         _Status = findViewById(R.id.Status);
  32.  
  33.         _Update = findViewById(R.id.EditProfile);
  34.         _Update.setOnClickListener(new View.OnClickListener() {
  35.             @Override
  36.             public void onClick(View view) {
  37.                 Intent Update = new Intent(MainActivity.this, UpdateActivity.class);
  38.                 Update.putExtra("fullname", fullname);
  39.                 Update.putExtra("username", username);
  40.                 Update.putExtra("age", age);
  41.                 Update.putExtra("status", status);
  42.                 startActivity(Update);
  43.             }
  44.         });
  45.  
  46.         _Exit = findViewById(R.id.SignOut);
  47.         _Exit.setOnClickListener(this);
  48.  
  49.         _DB = new DatabaseHelper(MainActivity.this);
  50.  
  51.         getData();
  52.  
  53.     }
  54.  
  55.     @Override
  56.     protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  57.         super.onActivityResult(requestCode, resultCode, data);
  58.         if (requestCode == 1) {
  59.             recreate();
  60.         }
  61.     }
  62.  
  63.     void getData() {
  64.         Cursor res = _DB.readData();
  65.         while (res.moveToNext()) {
  66.  
  67.             _ID.setText(res.getString(0));
  68.             _Name.setText(res.getString(1));
  69.             _Username.setText(res.getString(2));
  70.             _Age.setText(res.getString(3));
  71.             _Status.setText(res.getString(4));
  72.  
  73.         }
  74.     }
  75.  
  76.     @Override
  77.     public void onClick(View v) {
  78.         FirebaseAuth.getInstance().signOut();
  79.         Intent Exit = new Intent(MainActivity.this, LoginActivity.class);
  80.         startActivity(Exit);
  81.         finish();
  82.     }
  83. }
Advertisement
RAW Paste Data Copied
Advertisement