Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. XML code :-
  2.  
  3. <Button
  4. android:id="@+id/button"
  5. android:layout_width="match_parent"
  6. android:layout_height="wrap_content"
  7. android:layout_marginTop="250dp"
  8. android:text="+" />
  9.  
  10. <TextView
  11. android:id="@+id/textView"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:layout_marginTop="50dp"
  15. android:paddingLeft="200dp"
  16. android:textSize="25sp"
  17. android:text="0" />
  18.  
  19. Java code :-
  20.  
  21. import android.support.v7.app.AppCompatActivity;
  22. import android.os.Bundle;
  23. import android.view.View;
  24. import android.widget.Button;
  25. import android.widget.TextView;
  26.  
  27. public class MainActivity extends AppCompatActivity {
  28. Button btn;
  29. TextView txt;
  30.  
  31. protected int a = 1;
  32.  
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_main);
  37.  
  38. btn = (Button) findViewById(R.id.button);
  39. txt = (TextView) findViewById(R.id.textView);
  40.  
  41. }
  42.  
  43. public void display(final int n) {
  44. btn.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View v) {
  47. txt.setText(n);
  48. }
  49. });
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement