Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1.  
  2.  
  3. private EditText money, procent;
  4. private TextView answer;
  5. private Button btn;
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_calculator);
  11. init();
  12. btn.setOnClickListener(v -> answer());
  13. }
  14.  
  15. private void init() {
  16. money = findViewById(R.id.money);
  17. procent = findViewById(R.id.procent);
  18. answer = findViewById(R.id.answer);
  19. btn = findViewById(R.id.btn);
  20. }
  21.  
  22. private void answer(){
  23. System.out.println("===================== "+money.getText().toString());
  24. int qwe = Integer.parseInt(money.getText().toString());
  25. System.out.println(qwe);
  26. int asd = Integer.parseInt(procent.getText().toString());
  27. int Answer = qwe * asd / 100;
  28. answer.setText(String.valueOf(Answer));
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35. <?xml version="1.0" encoding="utf-8"?>
  36. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  37. xmlns:tools="http://schemas.android.com/tools"
  38. android:layout_width="match_parent"
  39. android:layout_height="match_parent"
  40. android:layout_row="2"
  41. tools:context=".calculator">
  42.  
  43. <LinearLayout
  44. android:layout_width="match_parent"
  45. android:layout_height="wrap_content"
  46. android:id="@+id/first">
  47.  
  48. <TextView
  49. android:layout_width="wrap_content"
  50. android:layout_height="wrap_content"
  51. android:text="Procent:" />
  52.  
  53. <EditText
  54. android:id="@+id/procent"
  55. android:layout_width="200px"
  56. android:layout_height="wrap_content" />
  57.  
  58. </LinearLayout>
  59.  
  60.  
  61.  
  62. <LinearLayout
  63. android:layout_width="match_parent"
  64. android:layout_height="wrap_content"
  65. android:layout_below="@+id/first"
  66. android:id="@+id/second">
  67.  
  68. <TextView
  69. android:layout_width="wrap_content"
  70. android:layout_height="50px"
  71. android:text="Money:" />
  72.  
  73. <EditText
  74. android:id="@+id/money"
  75. android:layout_width="200px"
  76. android:layout_height="wrap_content" />
  77.  
  78. </LinearLayout>
  79.  
  80. <Button
  81. android:layout_width="match_parent"
  82. android:layout_height="wrap_content"
  83. android:layout_below="@+id/second"
  84. android:id="@+id/btn"
  85. android:text="Go"
  86. />
  87.  
  88. <LinearLayout
  89. android:layout_width="match_parent"
  90. android:layout_height="wrap_content"
  91. android:layout_below="@+id/second"
  92. android:layout_marginTop="150px">
  93.  
  94. <TextView
  95. android:layout_width="wrap_content"
  96. android:layout_height="50px"
  97. android:text="Answer:" />
  98.  
  99. <TextView
  100. android:layout_width="match_parent"
  101. android:layout_height="wrap_content"
  102. android:id="@+id/answer"/>
  103.  
  104. </LinearLayout>
  105.  
  106.  
  107.  
  108. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement