SenpaiZero

MainActivity

Jun 3rd, 2024
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package com.example.a07act;
  2.  
  3. import android.content.ContentValues;
  4. import android.os.Bundle;
  5. import android.widget.TextView;
  6.  
  7. import androidx.appcompat.app.AppCompatActivity;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11. TextView one, two, three, four;
  12. SqliteHelper sqliteHelper;
  13. SqliteHelper.Queries query;
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. sqliteHelper = new SqliteHelper(this);
  20. query = new SqliteHelper.Queries(this);
  21.  
  22. SetUIVariables();
  23. populateData();
  24. setDataOne();
  25. setDataTwo();
  26. setDataThree();
  27. setDataFour();
  28. }
  29.  
  30. void setDataOne() {
  31. String s = "";
  32. for (String x : query.retrieveItemCode()) {
  33. s += x + "\n";
  34. }
  35. one.setText(s);
  36. }
  37.  
  38. void setDataTwo() {
  39. String s = "";
  40. for (String x : query.retrieveAllCol()) {
  41. s += x + "\n";
  42. }
  43. two.setText(s);
  44. }
  45.  
  46. void setDataThree() {
  47. String s = "";
  48. for (String x : query.retrieveAllCol(75)) {
  49. s += x + "\n";
  50. }
  51. three.setText(s);
  52. }
  53.  
  54. void setDataFour() {
  55. query.changePrice(101, 75);
  56. String s = "";
  57. for (String x : query.retrieveAllCol()) {
  58. s += x + "\n";
  59. }
  60. four.setText(s);
  61. }
  62.  
  63. void populateData() {
  64. ContentValues[] values = new ContentValues[4];
  65. values[0] = new ContentValues();
  66. values[0].put("ItemCode", 50);
  67. values[0].put("ItemDesc", "Laptop");
  68. values[0].put("Price", 150);
  69.  
  70. values[1] = new ContentValues();
  71. values[1].put("ItemCode", 63);
  72. values[1].put("ItemDesc", "Mouse");
  73. values[1].put("Price", 20);
  74.  
  75. values[2] = new ContentValues();
  76. values[2].put("ItemCode", 90);
  77. values[2].put("ItemDesc", "Headphone");
  78. values[2].put("Price", 45);
  79.  
  80. values[3] = new ContentValues();
  81. values[3].put("ItemCode", 101);
  82. values[3].put("ItemDesc", "Keyboard");
  83. values[3].put("Price", 85);
  84.  
  85. for (ContentValues v : values) {
  86. query.populateData(v);
  87. }
  88. }
  89.  
  90. void SetUIVariables() {
  91. one = findViewById(R.id.one);
  92. two = findViewById(R.id.two);
  93. three = findViewById(R.id.three);
  94. four = findViewById(R.id.four);
  95. }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment