MainActivity.java 892 B

1234567891011121314151617181920212223242526272829303132333435
  1. package org.uab.android.ui.uibutton;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.widget.Button;
  7. public class MainActivity extends Activity {
  8. Button pressMeButton;
  9. private int pressCount = 0;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. // Get a reference to the button in the UI
  15. pressMeButton = (Button) findViewById(R.id.button1);
  16. // Set an OnClickListener on this Button
  17. // Called each time the user clicks the Button
  18. pressMeButton.setOnClickListener(new OnClickListener() {
  19. @Override
  20. public void onClick(View v) {
  21. // Modify the label of the buttton to show the press count
  22. pressMeButton.setText("You pressed me: " + ++pressCount);
  23. }
  24. });
  25. }
  26. }