activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Число 1"
android:textSize="5mm" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="func1"
android:id="@+id/button1"
android:text="больше" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="func2"
android:id="@+id/button2"
android:text="меньше" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="func3"
android:text="равно" />
</LinearLayout>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="результат сравнения"
android:textSize="5mm" />
</LinearLayout>
MainActivity
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
int relation = 0;
int random_number1 = 0;
int random_number2 = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainfunc();
}
public void mainfunc() {
random_number1 = 1 + (int) (Math.random() * 10);
random_number2 = 1 + (int) (Math.random() * 10);
TextView textView1 = findViewById(R.id.textView1);
textView1.setText(Integer.toString(random_number1)+" "+Integer.toString(random_number2));
if (random_number1 > random_number2) {
relation = 1;
}
if (random_number1 < random_number2) {
relation = 2;
}
if (random_number1 == random_number2) {
relation = 3;
}
}
public void func1(View v) {
if (relation == 1) {
TextView infoTextView = (TextView) findViewById(R.id.textView3);
infoTextView.setText("Правильно");
} else {
TextView infoTextView = (TextView) findViewById(R.id.textView3);
infoTextView.setText("Неправильно");
}
mainfunc();
}
public void func2(View v) {
if (relation == 2) {
TextView infoTextView = (TextView) findViewById(R.id.textView3);
infoTextView.setText("Правильно");
} else {
TextView infoTextView = (TextView) findViewById(R.id.textView3);
infoTextView.setText("Неправильно");
}
mainfunc();
}
public void func3(View v) {
if (relation == 3) {
TextView infoTextView = (TextView) findViewById(R.id.textView3);
infoTextView.setText("Правильно");
} else {
TextView infoTextView = (TextView) findViewById(R.id.textView3);
infoTextView.setText("Неправильно");
}
mainfunc();
}
}
|