parent
de03776d29
commit
ed47dea6f6
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue