Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package com.example.zadanie1;
  2.  
  3. import androidx.annotation.Nullable;
  4. import androidx.appcompat.app.AppCompatActivity;
  5.  
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.ImageView;
  10.  
  11. import java.util.Random;
  12.  
  13.  
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16. ImageView img;
  17. Random rand;
  18. int[] obrazki = new int[]{R.drawable.kot01,R.drawable.kot02,R.drawable.kot03};
  19. int idObrazka;
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_main);
  24. img = findViewById(R.id.imageView01);
  25. Losuj();
  26. }
  27.  
  28. public void LosujObrazek(View view) {
  29. Losuj();
  30. }
  31.  
  32. private void Losuj(){
  33. rand = new Random();
  34. idObrazka = obrazki[rand.nextInt(3)];
  35. img.setImageResource(idObrazka);
  36. }
  37.  
  38. public void PowiekszObrazek(View view) {
  39. Intent intencja = new Intent(this, Main2Activity.class);
  40. intencja.putExtra("data", idObrazka);
  41. startActivity(intencja);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement