Advertisement
kaburen

lab3

Mar 10th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity">
  8.  
  9.     <TextView
  10.         android:id="@+id/genText"
  11.         android:layout_width="246dp"
  12.         android:layout_height="148dp"
  13.         android:text="@string/defaultMes"
  14.         app:layout_constraintBottom_toBottomOf="parent"
  15.         app:layout_constraintHorizontal_bias="0.503"
  16.         app:layout_constraintLeft_toLeftOf="parent"
  17.         app:layout_constraintRight_toRightOf="parent"
  18.         app:layout_constraintTop_toTopOf="parent"
  19.         app:layout_constraintVertical_bias="0.302" />
  20.  
  21.     <Button
  22.         android:id="@+id/genButton"
  23.         android:layout_width="96dp"
  24.         android:layout_height="97dp"
  25.         android:layout_marginBottom="96dp"
  26.         android:background="@drawable/shaperound"
  27.         android:text="@string/genKey"
  28.         app:layout_constraintBottom_toBottomOf="parent"
  29.         app:layout_constraintEnd_toEndOf="parent"
  30.         app:layout_constraintStart_toStartOf="parent" />
  31.  
  32.     <TextView
  33.         android:id="@+id/textView"
  34.         android:layout_width="wrap_content"
  35.         android:layout_height="wrap_content"
  36.         android:text="@string/transtxt"
  37.         app:layout_constraintBottom_toBottomOf="parent"
  38.         app:layout_constraintEnd_toEndOf="parent"
  39.         app:layout_constraintHorizontal_bias="0.502"
  40.         app:layout_constraintStart_toStartOf="parent"
  41.         app:layout_constraintTop_toBottomOf="@+id/genButton"
  42.         app:layout_constraintVertical_bias="0.751" />
  43.  
  44. </androidx.constraintlayout.widget.ConstraintLayout>
  45. -------------------------------------------------------------
  46. package com.example.lab3t;
  47.  
  48. import androidx.appcompat.app.AppCompatActivity;
  49.  
  50. import android.os.Bundle;
  51. import android.view.View;
  52. import android.widget.Button;
  53. import android.widget.TextView;
  54.  
  55. import java.util.Random;
  56.  
  57.  
  58. public class MainActivity extends AppCompatActivity {
  59.     Button genBut;
  60.     TextView genTxt;
  61.  
  62.     @Override
  63.     protected void onCreate(Bundle savedInstanceState) {
  64.         super.onCreate(savedInstanceState);
  65.         setContentView(R.layout.activity_main);
  66.         final Random rand = new Random();
  67.  
  68.         genBut = (Button)findViewById(R.id.genButton);
  69.         genTxt = (TextView)findViewById(R.id.genText);
  70.         final String[] jokTab = new String [4];
  71.  
  72.         jokTab[0] = getString(R.string.dry1);
  73.         jokTab[1] = getString(R.string.dry2);
  74.         jokTab[2] = getString(R.string.dry3);
  75.         jokTab[3] = getString(R.string.dry4);
  76.  
  77.  
  78.         genBut.setOnClickListener(
  79.                 new View.OnClickListener(){
  80.                     @Override
  81.                     public void onClick(View v) {
  82.                         int randomint = rand.nextInt(4);
  83.                         genTxt.setText(jokTab[randomint]);
  84.                     }
  85.                 });
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement