Advertisement
xerpi

java test

Sep 10th, 2011
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package pongdroid.com;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.LinearLayout;
  9. import android.widget.TextView;
  10.  
  11. public class PongDroidActivity extends Activity implements OnClickListener {
  12.     //Creamos un int que contendrá las veces pulsadas 
  13.         public int pulsado;
  14.    
  15.     @Override
  16.     public void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.             //Creamos un LinearLayout llamado layout
  19.                 LinearLayout layout = new LinearLayout(this);
  20.             //Creamos un TextView llamado textView
  21.                 TextView textView = new TextView(this);
  22.             //Definimos orientación del layout
  23.                 layout.setOrientation(LinearLayout.VERTICAL);
  24.             //Creamos un nuevo Button
  25.                 Button buton = new Button(this);
  26.             //Seteamos el texto del textView
  27.                 textView.setText("Veces pulsado: " + pulsado);
  28.             //Insertamos el textView en el layout          
  29.                 layout.addView(textView);    
  30.             //Insertamos el buton al layout
  31.                 layout.addView(buton);
  32.             //Ponemos "Pulsa" en el buton
  33.                 buton.setText("Pulsa");
  34.             //Añadimos un listener al buton ( para chequear si se pulsa)
  35.                 buton.setOnClickListener(this);
  36.             //Mostramos el layout :)
  37.                 setContentView(layout);
  38.     }
  39.    
  40.     public void update(Button buton) {
  41.         pulsado++;
  42.        
  43.     }
  44.    
  45.     @Override
  46.     public void onClick(View arg0) {
  47.         update((Button) arg0);
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement