Advertisement
Guest User

Untitled

a guest
May 27th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout 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="com.example.administrator.test.MainActivity">
  8.  
  9. <EditText
  10. android:layout_width="250dp"
  11. android:layout_height="wrap_content"
  12. android:hint="First Number"
  13. android:textSize="20dp"
  14. android:layout_marginTop="27dp"
  15. android:id="@+id/n1"
  16. android:layout_alignParentTop="true"
  17. android:layout_alignLeft="@+id/plus"
  18. android:layout_alignStart="@+id/plus"
  19. android:layout_alignRight="@+id/n2"
  20. android:layout_alignEnd="@+id/n2" />
  21.  
  22. <EditText
  23. android:layout_width="250dp"
  24. android:layout_height="wrap_content"
  25. android:hint="Second Number"
  26. android:textSize="20dp"
  27. android:id="@+id/n2"
  28. android:layout_marginTop="25dp"
  29. android:layout_below="@+id/n1"
  30. android:layout_alignLeft="@+id/plus"
  31. android:layout_alignStart="@+id/plus"
  32. android:layout_alignRight="@+id/minus"
  33. android:layout_alignEnd="@+id/minus" />
  34.  
  35. <Button
  36. android:id="@+id/plus"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:layout_marginTop="33dp"
  40. android:text="+"
  41. android:textSize="30dp"
  42. android:layout_below="@+id/n2"
  43. android:layout_alignParentLeft="true"
  44. android:layout_alignParentStart="true"
  45. android:layout_marginLeft="46dp"
  46. android:layout_marginStart="46dp" />
  47.  
  48. <Button
  49. android:id="@+id/minus"
  50. android:layout_width="wrap_content"
  51. android:layout_height="wrap_content"
  52. android:layout_alignBottom="@+id/plus"
  53. android:layout_alignParentEnd="true"
  54. android:layout_alignParentRight="true"
  55. android:layout_marginEnd="73dp"
  56. android:layout_marginRight="73dp"
  57. android:textSize="30dp"
  58. android:text="-" />
  59.  
  60. <Button
  61. android:id="@+id/mul"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:layout_alignEnd="@+id/plus"
  65. android:layout_alignRight="@+id/plus"
  66. android:layout_below="@+id/plus"
  67. android:layout_marginTop="24dp"
  68. android:textSize="30dp"
  69. android:text="*" />
  70.  
  71. <Button
  72. android:id="@+id/div"
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:layout_alignLeft="@+id/minus"
  76. android:layout_alignStart="@+id/minus"
  77. android:layout_alignTop="@+id/mul"
  78. android:textSize="30dp"
  79. android:text="/" />
  80.  
  81. <TextView
  82. android:id="@+id/ans"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:textSize="30dp"
  86. android:text="Result"
  87. android:layout_below="@+id/div"
  88. android:layout_toLeftOf="@+id/div"
  89. android:layout_toStartOf="@+id/div"
  90. android:layout_marginTop="75dp" />
  91.  
  92.  
  93. </RelativeLayout>
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. package com.example.administrator.test;
  103.  
  104. import android.support.v7.app.AppCompatActivity;
  105. import android.os.Bundle;
  106. import android.widget.Button;
  107. import android.widget.EditText;
  108. import android.widget.TextView;
  109.  
  110. public class MainActivity extends AppCompatActivity {
  111.  
  112. public EditText e1;
  113. public EditText e2;
  114. public Button b1;
  115. public Button b2;
  116. public Button b3;
  117. public Button b4;
  118. public TextView res;
  119.  
  120. public double result;
  121.  
  122. @Override
  123. protected void onCreate(Bundle savedInstanceState) {
  124. super.onCreate(savedInstanceState);
  125. setContentView(R.layout.activity_main);
  126. e1 = (EditText)findViewById(R.id.n1);
  127. e2 = (EditText)findViewById(R.id.n2);
  128. b1 = (Button)findViewById(R.id.plus);
  129. b2 = (Button)findViewById(R.id.minus);
  130. b3 = (Button)findViewById(R.id.mul);
  131. b4 = (Button)findViewById(R.id.div);
  132. res =(TextView)findViewById(R.id.ans);
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement