Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:id="@+id/genText"
- android:layout_width="246dp"
- android:layout_height="148dp"
- android:text="@string/defaultMes"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintHorizontal_bias="0.503"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="0.302" />
- <Button
- android:id="@+id/genButton"
- android:layout_width="96dp"
- android:layout_height="97dp"
- android:layout_marginBottom="96dp"
- android:background="@drawable/shaperound"
- android:text="@string/genKey"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent" />
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/transtxt"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.502"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/genButton"
- app:layout_constraintVertical_bias="0.751" />
- </androidx.constraintlayout.widget.ConstraintLayout>
- -------------------------------------------------------------
- package com.example.lab3t;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import java.util.Random;
- public class MainActivity extends AppCompatActivity {
- Button genBut;
- TextView genTxt;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Random rand = new Random();
- genBut = (Button)findViewById(R.id.genButton);
- genTxt = (TextView)findViewById(R.id.genText);
- final String[] jokTab = new String [4];
- jokTab[0] = getString(R.string.dry1);
- jokTab[1] = getString(R.string.dry2);
- jokTab[2] = getString(R.string.dry3);
- jokTab[3] = getString(R.string.dry4);
- genBut.setOnClickListener(
- new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- int randomint = rand.nextInt(4);
- genTxt.setText(jokTab[randomint]);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement