From ed47dea6f6f1453321a66a005f75ffa09810a2b5 Mon Sep 17 00:00:00 2001 From: pethkqnpj Date: Wed, 13 Oct 2021 10:21:33 +0800 Subject: [PATCH] ADD file via upload --- MenuActivity.java | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 MenuActivity.java diff --git a/MenuActivity.java b/MenuActivity.java new file mode 100644 index 0000000..02e67fe --- /dev/null +++ b/MenuActivity.java @@ -0,0 +1,61 @@ +package com.example.WhatMeal; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.ContentValues; +import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; +import java.util.Random; + +public class EatWhatActivity extends AppCompatActivity +{ + MenuActivity.MyHelper myHelper; + private TextView text_food; + private TextView text_store; + private Button btn_change; + private Button b4; + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_eatwhat); + myHelper = new com.example.WhatMeal.MenuActivity.MyHelper(this); + text_food = (TextView) findViewById(R.id.text_food); + text_store = (TextView) findViewById(R.id.text_store); + btn_change = (Button) findViewById(R.id.btn_change); + btn_change.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + SQLiteDatabase db = myHelper.getReadableDatabase(); + Cursor c = db.query("information", null, null, null, null, null, null); + int n = c.getCount() + 1; + Random R = new Random(); + int i = R.nextInt(n - 1) + 1; + c.moveToPosition(i); + text_food.setText( "" + c.getString(1)); + text_store.setText("" + c.getString(2)); + c.close(); + db.close(); + } + }); + + b4 = (Button) findViewById(R.id.b4); + b4.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + Intent intent = new Intent(EatWhatActivity.this, MainActivity.class); + startActivity(intent); + } + }); + } +} \ No newline at end of file