Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. <Button
  2. android:id="@+id/button"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:layout_marginTop="250dp"
  6. android:text="+" />
  7.  
  8. <TextView
  9. android:id="@+id/textView"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:layout_marginTop="50dp"
  13. android:paddingLeft="200dp"
  14. android:textSize="25sp"
  15. android:text="0" />
  16.  
  17. import android.support.v7.app.AppCompatActivity;
  18. import android.os.Bundle;
  19. import android.view.View;
  20. import android.widget.Button;
  21. import android.widget.TextView;
  22.  
  23. public class MainActivity extends AppCompatActivity {
  24. Button btn;
  25. TextView txt;
  26.  
  27. protected int a = 1;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_main);
  33.  
  34. btn = (Button) findViewById(R.id.button);
  35. txt = (TextView) findViewById(R.id.textView);
  36.  
  37. }
  38.  
  39. public void display(final int n) {
  40. btn.setOnClickListener(new View.OnClickListener() {
  41. @Override
  42. public void onClick(View v) {
  43. txt.setText(n);
  44. }
  45. });
  46. }
  47.  
  48. public void increment(View view) {
  49. a = a + 1;
  50. display(a);
  51. }
  52. }
  53.  
  54. public class MainActivity extends AppCompatActivity {
  55. Button btn;
  56. TextView txt;
  57.  
  58. protected int a = 1;
  59.  
  60. @Override
  61. protected void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63. setContentView(R.layout.activity_main);
  64.  
  65. btn = (Button) findViewById(R.id.button);
  66. txt = (TextView) findViewById(R.id.textView);
  67.  
  68. btn.setOnClickListener(new View.OnClickListener() {
  69. @Override
  70. public void onClick(View v) {
  71. a++;
  72. display(a);
  73. }
  74. });
  75.  
  76. }
  77.  
  78. public void display(int n) {
  79. txt.setText(n);
  80. }
  81. }
  82.  
  83. import android.support.v7.app.AppCompatActivity;
  84. import android.os.Bundle;
  85. import android.view.View;
  86. import android.widget.Button;
  87. import android.widget.TextView;
  88.  
  89. public class MainActivity extends AppCompatActivity {
  90. Button btn;
  91. TextView txt;
  92.  
  93. protected int a = 1;
  94.  
  95. @Override
  96. protected void onCreate(Bundle savedInstanceState) {
  97. super.onCreate(savedInstanceState);
  98. setContentView(R.layout.activity_main);
  99.  
  100. btn = (Button) findViewById(R.id.button);
  101. txt = (TextView) findViewById(R.id.textView);
  102.  
  103. btn.setOnClickListener(new View.OnClickListener() {
  104. @Override
  105. public void onClick(View v) {
  106. txt.setText(String.valueOf(++a));
  107. }
  108. });
  109. }
  110. }
  111.  
  112. import android.support.v7.app.AppCompatActivity;
  113. import android.os.Bundle;
  114. import android.view.View;
  115. import android.widget.Button;
  116. import android.widget.TextView;
  117.  
  118. public class MainActivity extends AppCompatActivity {
  119. Button btn;
  120. TextView txt;
  121.  
  122. protected int a = 1;
  123.  
  124. @Override
  125. protected void onCreate(Bundle savedInstanceState) {
  126. super.onCreate(savedInstanceState);
  127. setContentView(R.layout.activity_main);
  128.  
  129. btn = (Button) findViewById(R.id.button);
  130. txt = (TextView) findViewById(R.id.textView);
  131.  
  132. btn.setOnClickListener(new View.OnClickListener() {
  133. @Override
  134. public void onClick(View v) {
  135. a = a + 1;
  136. txt.setText(a);
  137. }
  138. });
  139.  
  140. }
  141.  
  142. }
  143.  
  144. public class MainActivity extends AppCompatActivity {
  145. Button btn;
  146. TextView txt;
  147. protected int a = 1;
  148.  
  149. @Override
  150. protected void onCreate(Bundle savedInstanceState) {
  151. super.onCreate(savedInstanceState);
  152. setContentView(R.layout.activity_main);
  153.  
  154. btn = (Button) findViewById(R.id.button);
  155. txt = (TextView) findViewById(R.id.textView);
  156.  
  157. btn.setOnClickListener(new View.OnClickListener() {
  158. @Override
  159. public void onClick(View v) {
  160. a++;
  161. txt.setText(a+"");
  162. }
  163. });
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement