Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.a07act;
- import android.content.ContentValues;
- import android.os.Bundle;
- import android.widget.TextView;
- import androidx.appcompat.app.AppCompatActivity;
- public class MainActivity extends AppCompatActivity {
- TextView one, two, three, four;
- SqliteHelper sqliteHelper;
- SqliteHelper.Queries query;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- sqliteHelper = new SqliteHelper(this);
- query = new SqliteHelper.Queries(this);
- SetUIVariables();
- populateData();
- setDataOne();
- setDataTwo();
- setDataThree();
- setDataFour();
- }
- void setDataOne() {
- String s = "";
- for (String x : query.retrieveItemCode()) {
- s += x + "\n";
- }
- one.setText(s);
- }
- void setDataTwo() {
- String s = "";
- for (String x : query.retrieveAllCol()) {
- s += x + "\n";
- }
- two.setText(s);
- }
- void setDataThree() {
- String s = "";
- for (String x : query.retrieveAllCol(75)) {
- s += x + "\n";
- }
- three.setText(s);
- }
- void setDataFour() {
- query.changePrice(101, 75);
- String s = "";
- for (String x : query.retrieveAllCol()) {
- s += x + "\n";
- }
- four.setText(s);
- }
- void populateData() {
- ContentValues[] values = new ContentValues[4];
- values[0] = new ContentValues();
- values[0].put("ItemCode", 50);
- values[0].put("ItemDesc", "Laptop");
- values[0].put("Price", 150);
- values[1] = new ContentValues();
- values[1].put("ItemCode", 63);
- values[1].put("ItemDesc", "Mouse");
- values[1].put("Price", 20);
- values[2] = new ContentValues();
- values[2].put("ItemCode", 90);
- values[2].put("ItemDesc", "Headphone");
- values[2].put("Price", 45);
- values[3] = new ContentValues();
- values[3].put("ItemCode", 101);
- values[3].put("ItemDesc", "Keyboard");
- values[3].put("Price", 85);
- for (ContentValues v : values) {
- query.populateData(v);
- }
- }
- void SetUIVariables() {
- one = findViewById(R.id.one);
- two = findViewById(R.id.two);
- three = findViewById(R.id.three);
- four = findViewById(R.id.four);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment