Advertisement
Guest User

bartosz

a guest
Jan 27th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.80 KB | None | 0 0
  1. package com.example.tomek;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.ImageView;
  9. import android.widget.RadioButton;
  10.  
  11. import java.util.Random;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15.  
  16. ImageView galeria;
  17. RadioButton jeden, dwa, trzy, cztery;
  18. int b;
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23. galeria = findViewById(R.id.grafika);
  24. Random rand = new Random();
  25.  
  26. int a = rand.nextInt(4);
  27. switch(a){
  28. case 0:
  29. galeria.setImageResource(R.drawable.kw1);
  30. break;
  31. case 1:
  32. galeria.setImageResource(R.drawable.kw2);
  33. break;
  34. case 2:
  35. galeria.setImageResource(R.drawable.kw3);
  36. break;
  37. case 3:
  38. galeria.setImageResource(R.drawable.kw4);
  39. break;
  40.  
  41. }
  42. jeden = findViewById(R.id.opcja01);
  43. dwa = findViewById(R.id.opcja02);
  44. trzy = findViewById(R.id.opcja03);
  45. cztery = findViewById(R.id.opcja04);
  46.  
  47.  
  48. }
  49.  
  50. public void checkPhoto(View view) {
  51. if(jeden.isChecked() == true){
  52. galeria.setImageResource(R.drawable.kw1);
  53. b=1;
  54. }
  55. else if(dwa.isChecked()==true){
  56. galeria.setImageResource(R.drawable.kw2);
  57. b=2;
  58. }
  59. else if(trzy.isChecked()==true)
  60. galeria.setImageResource(R.drawable.kw3);
  61. else if(cztery.isChecked()==true)
  62. galeria.setImageResource(R.drawable.kw4);
  63. }
  64.  
  65. public void nowaAktywnosc(View view) {
  66. Intent intencja = new Intent(this,Main2Activity.class);
  67. intencja.putExtra("wartosc", b);
  68. startActivity(intencja);
  69. }
  70. }
  71.  
  72.  
  73. ***************************************************MA
  74. <?xml version="1.0" encoding="utf-8"?>
  75. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  76. xmlns:app="http://schemas.android.com/apk/res-auto"
  77. xmlns:tools="http://schemas.android.com/tools"
  78. android:layout_width="match_parent"
  79. android:layout_height="match_parent"
  80. tools:context=".MainActivity">
  81.  
  82. <androidx.constraintlayout.widget.Guideline
  83. android:id="@+id/guideline01"
  84. android:layout_width="wrap_content"
  85. android:layout_height="wrap_content"
  86. android:orientation="horizontal"
  87. app:layout_constraintGuide_percent=".5" />
  88. <androidx.constraintlayout.widget.Guideline
  89. android:id="@+id/guideline03"
  90. android:layout_width="wrap_content"
  91. android:layout_height="wrap_content"
  92. android:orientation="vertical"
  93. app:layout_constraintGuide_percent="0.8" />
  94.  
  95. <androidx.constraintlayout.widget.Guideline
  96. android:id="@+id/guideline02"
  97. android:layout_width="wrap_content"
  98. android:layout_height="wrap_content"
  99. android:orientation="vertical"
  100. app:layout_constraintGuide_percent=".6" />
  101.  
  102. <ImageView
  103. android:id="@+id/grafika"
  104. android:layout_width="0dp"
  105. android:layout_height="0dp"
  106. app:layout_constraintBottom_toBottomOf="@id/guideline01"
  107. app:layout_constraintLeft_toLeftOf="parent"
  108. app:layout_constraintRight_toRightOf="@id/guideline02"
  109. app:layout_constraintTop_toTopOf="parent"
  110. android:onClick="nowaAktywnosc"/>
  111.  
  112. <RadioGroup
  113. android:id="@+id/radio01"
  114. android:layout_width="0dp"
  115. android:layout_height="wrap_content"
  116. android:padding="30dp"
  117. app:layout_constraintBottom_toBottomOf="@id/guideline01"
  118. app:layout_constraintLeft_toLeftOf="@id/guideline02"
  119. app:layout_constraintRight_toRightOf="parent"
  120. app:layout_constraintTop_toTopOf="parent">
  121.  
  122. <RadioButton
  123. android:id="@+id/opcja01"
  124. android:layout_width="wrap_content"
  125. android:layout_height="wrap_content"
  126. android:text="Rys. 1"
  127. android:textSize="20dp"
  128. android:onClick="checkPhoto"/>
  129.  
  130. <RadioButton
  131. android:id="@+id/opcja02"
  132. android:layout_width="wrap_content"
  133. android:layout_height="wrap_content"
  134. android:text="Rys. 2"
  135. android:textSize="20dp"
  136. android:onClick="checkPhoto"/>
  137.  
  138. <RadioButton
  139. android:id="@+id/opcja03"
  140. android:layout_width="wrap_content"
  141. android:layout_height="wrap_content"
  142. android:text="Rys. 3"
  143. android:textSize="20dp"
  144. android:onClick="checkPhoto"/>
  145.  
  146. <RadioButton
  147. android:id="@+id/opcja04"
  148. android:layout_width="wrap_content"
  149. android:layout_height="wrap_content"
  150. android:text="Rys. 4"
  151. android:textSize="20dp"
  152. android:onClick="checkPhoto"/>
  153. </RadioGroup>
  154.  
  155. <SeekBar
  156. android:id="@+id/bar01"
  157. android:layout_width="0dp"
  158. android:layout_height="40dp"
  159. app:layout_constraintLeft_toLeftOf="parent"
  160. app:layout_constraintRight_toRightOf="@id/guideline03"
  161. app:layout_constraintTop_toTopOf="@id/guideline01" />
  162.  
  163. <SeekBar
  164. android:id="@+id/bar02"
  165. android:layout_width="0dp"
  166. android:layout_height="40dp"
  167. app:layout_constraintLeft_toLeftOf="parent"
  168. app:layout_constraintRight_toRightOf="@id/guideline03"
  169. app:layout_constraintTop_toBottomOf="@id/bar01" />
  170.  
  171. <SeekBar
  172. android:id="@+id/bar03"
  173. android:layout_width="0dp"
  174. android:layout_height="40dp"
  175. app:layout_constraintLeft_toLeftOf="parent"
  176. app:layout_constraintRight_toRightOf="@id/guideline03"
  177. app:layout_constraintTop_toBottomOf="@id/bar02" />
  178.  
  179.  
  180. <TextView
  181. android:id="@+id/textR"
  182. android:layout_width="wrap_content"
  183. android:layout_height="wrap_content"
  184. app:layout_constraintLeft_toRightOf="@id/bar01"
  185. app:layout_constraintTop_toTopOf="@id/bar01"
  186. android:text="R"
  187. android:textSize="30dp"/>
  188. <TextView
  189. android:id="@+id/textG"
  190. android:layout_width="wrap_content"
  191. android:layout_height="wrap_content"
  192. app:layout_constraintLeft_toRightOf="@id/bar01"
  193. app:layout_constraintTop_toTopOf="@id/bar02"
  194. android:text="G"
  195. android:textSize="30dp"/>
  196. <TextView
  197. android:id="@+id/textB"
  198. android:layout_width="wrap_content"
  199. android:layout_height="wrap_content"
  200. app:layout_constraintLeft_toRightOf="@id/bar01"
  201. app:layout_constraintTop_toTopOf="@id/bar03"
  202. android:text="B"
  203. android:textSize="30dp"/>
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. </androidx.constraintlayout.widget.ConstraintLayout>
  211. **********************************************************activity_main
  212. package com.example.tomek;
  213.  
  214. import androidx.appcompat.app.AppCompatActivity;
  215.  
  216. import android.os.Bundle;
  217. import android.widget.ImageView;
  218.  
  219. public class Main2Activity extends AppCompatActivity {
  220.  
  221. ImageView galeria;
  222.  
  223. @Override
  224. protected void onCreate(Bundle savedInstanceState) {
  225. super.onCreate(savedInstanceState);
  226. setContentView(R.layout.activity_main2);
  227. Bundle paczka =getIntent().getExtras();
  228. galeria = findViewById(R.id.grafika);
  229. int pb =paczka.getInt("wartosc");
  230. if (pb==1)
  231. galeria.setImageResource(R.drawable.kw1);
  232. else if (pb==2)
  233. galeria.setImageResource(R.drawable.kw2);
  234. }
  235. }
  236. **************************************************************MainA2
  237. <?xml version="1.0" encoding="utf-8"?>
  238. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  239. xmlns:app="http://schemas.android.com/apk/res-auto"
  240. xmlns:tools="http://schemas.android.com/tools"
  241. android:layout_width="match_parent"
  242. android:layout_height="match_parent"
  243. tools:context=".Main2Activity">
  244. <ImageView
  245. android:id="@+id/grafika"
  246. android:layout_width="0dp"
  247. android:layout_height="0dp"
  248. app:layout_constraintBottom_toBottomOf="parent"
  249. app:layout_constraintLeft_toLeftOf="parent"
  250. app:layout_constraintRight_toRightOf="parent"
  251. app:layout_constraintTop_toTopOf="parent"
  252. />
  253. </androidx.constraintlayout.widget.ConstraintLayout>
  254. ************************************************************************activity_main2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement