Advertisement
Guest User

Zad Km/s, m/s

a guest
Dec 5th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 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. <EditText
  10. android:id="@+id/editText01"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:textSize="15pt"
  14. android:ems="5"
  15. android:inputType="number"
  16. app:layout_constraintLeft_toLeftOf="parent"
  17. app:layout_constraintTop_toTopOf="parent"
  18. />
  19.  
  20. <TextView
  21. android:id="@+id/textView01"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:text="km/h"
  25. android:textSize="15pt"
  26. app:layout_constraintLeft_toRightOf="@id/editText01"
  27. app:layout_constraintTop_toTopOf="parent"
  28. android:layout_margin="5pt"
  29. />
  30.  
  31. <Button
  32. android:id="@+id/button01"
  33. android:layout_width="0pt"
  34. android:layout_height="wrap_content"
  35. android:text="Oblicz"
  36. android:textSize="10pt"
  37. android:layout_margin="5pt"
  38. app:layout_constraintTop_toBottomOf="@id/editText01"
  39. app:layout_constraintLeft_toLeftOf="parent"
  40. app:layout_constraintRight_toRightOf="parent"
  41. android:onClick="calculate"
  42. />
  43.  
  44. <TextView
  45. android:id="@+id/textView02"
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:text=".............."
  49. android:textSize="15pt"
  50. app:layout_constraintLeft_toLeftOf="parent"
  51. app:layout_constraintTop_toBottomOf="@id/button01"
  52. android:layout_margin="5pt"
  53. />
  54.  
  55. <TextView
  56. android:id="@+id/textView03"
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:text="m/s"
  60. android:textSize="15pt"
  61. app:layout_constraintLeft_toRightOf="@id/textView02"
  62. app:layout_constraintTop_toBottomOf="@id/button01"
  63. android:layout_margin="5pt"
  64. />
  65.  
  66. </androidx.constraintlayout.widget.ConstraintLayout>
  67.  
  68.  
  69.  
  70.  
  71. ****************************************************************
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. package com.example.k03;
  79.  
  80. import androidx.appcompat.app.AppCompatActivity;
  81.  
  82. import android.os.Bundle;
  83. import android.view.View;
  84. import android.widget.EditText;
  85. import android.widget.TextView;
  86.  
  87. public class MainActivity extends AppCompatActivity {
  88.  
  89. @Override
  90. protected void onCreate(Bundle savedInstanceState) {
  91. super.onCreate(savedInstanceState);
  92. setContentView(R.layout.activity_main);
  93. }
  94.  
  95. public void calculate(View view) {
  96. double xx = 0;
  97.  
  98. EditText liczba = findViewById(R.id.editText01);
  99. TextView wynik = findViewById(R.id.textView02);
  100.  
  101. String x;
  102. x = liczba.getText().toString();
  103. xx = Double.parseDouble(x);
  104.  
  105. xx=xx*1000/3600;
  106.  
  107. wynik.setText(String.valueOf(xx));
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement