Guest User

Untitled

a guest
Mar 29th, 2013
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package com.german.tutorial;
  2.  
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.view.Menu;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9.  
  10. public class Main extends Activity {
  11.  
  12.     int counter;   
  13.     Button add, sub;
  14.     TextView display;
  15.    
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.main);
  20.         counter = 0;
  21.         add = (Button) findViewById(R.id.bAdd);
  22.         display = (TextView) findViewById(R.id.tvDisplay);
  23.         add.setOnClickListener(new View.OnClickListener() {
  24.            
  25.             @Override
  26.             public void onClick(View v) {
  27.                 // TODO Auto-generated method stub
  28.                 counter++;
  29.                 display.setText("Your total is " + counter);
  30.             }
  31.         });
  32.         sub.setOnClickListener(new View.OnClickListener() {
  33.            
  34.             @Override
  35.             public void onClick(View v) {
  36.                 // TODO Auto-generated method stub
  37.                 counter--;
  38.                 display.setText("Your total is " + counter);
  39.             }
  40.         });
  41.     }
  42.  
  43.     @Override
  44.     public boolean onCreateOptionsMenu(Menu menu) {
  45.         // Inflate the menu; this adds items to the action bar if it is present.
  46.         getMenuInflater().inflate(R.menu.main, menu);
  47.         return true;
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment