Advertisement
iNoobAvicena

Update

Nov 18th, 2021
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package com.example.tugassqlfirebase;
  2.  
  3. import android.content.Intent;
  4. import android.database.Cursor;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9.  
  10. import androidx.appcompat.app.AppCompatActivity;
  11.  
  12. public class UpdateActivity extends AppCompatActivity {
  13.  
  14.     Button _Confirm, _Cancel;
  15.     EditText _fnInput, _unInput, _agInput, _stInput;
  16.     String _fn, _un, _ag, _st, _id;
  17.  
  18.     DatabaseHelper _DB;
  19.  
  20.     @Override
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_update);
  24.  
  25.         _fnInput = findViewById(R.id.FullnameInput);
  26.         _unInput = findViewById(R.id.UsernameInput);
  27.         _agInput = findViewById(R.id.AgeInput);
  28.         _stInput = findViewById(R.id.StatusInput);
  29.         _Confirm = findViewById(R.id.Update);
  30.         _Cancel = findViewById(R.id.Cancel);
  31.  
  32.         _DB = new DatabaseHelper(UpdateActivity.this);
  33.  
  34.         getData();
  35.  
  36.         _Confirm.setOnClickListener(new View.OnClickListener() {
  37.             @Override
  38.             public void onClick(View view) {
  39.  
  40.                 _fn = _fnInput.getText().toString();
  41.                 _un = _unInput.getText().toString();
  42.                 _ag = _agInput.getText().toString();
  43.                 _st = _stInput.getText().toString();
  44.  
  45.                 _DB.updateData(_id, _fn, _un, _ag, _st);
  46.  
  47.                 Intent Menu = new Intent(UpdateActivity.this, MainActivity.class);
  48.                 startActivity(Menu);
  49.                 finish();
  50.             }
  51.         });
  52.  
  53.         _Cancel.setOnClickListener(new View.OnClickListener() {
  54.             @Override
  55.             public void onClick(View view) {
  56.                 finish();
  57.             }
  58.         });
  59.     }
  60.  
  61.     void getData() {
  62.         DatabaseHelper DB = new DatabaseHelper(UpdateActivity.this);
  63.         Cursor res = DB.readData();
  64.         while(res.moveToNext()) {
  65.  
  66.             _fnInput.setText(res.getString(1));
  67.             _unInput.setText(res.getString(2));
  68.             _agInput.setText(res.getString(3));
  69.             _stInput.setText(res.getString(4));
  70.  
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement