Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pongdroid.com;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- public class PongDroidActivity extends Activity implements OnClickListener {
- //Creamos un int que contendrá las veces pulsadas
- public int pulsado;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //Creamos un LinearLayout llamado layout
- LinearLayout layout = new LinearLayout(this);
- //Creamos un TextView llamado textView
- TextView textView = new TextView(this);
- //Definimos orientación del layout
- layout.setOrientation(LinearLayout.VERTICAL);
- //Creamos un nuevo Button
- Button buton = new Button(this);
- //Seteamos el texto del textView
- textView.setText("Veces pulsado: " + pulsado);
- //Insertamos el textView en el layout
- layout.addView(textView);
- //Insertamos el buton al layout
- layout.addView(buton);
- //Ponemos "Pulsa" en el buton
- buton.setText("Pulsa");
- //Añadimos un listener al buton ( para chequear si se pulsa)
- buton.setOnClickListener(this);
- //Mostramos el layout :)
- setContentView(layout);
- }
- public void update(Button buton) {
- pulsado++;
- }
- @Override
- public void onClick(View arg0) {
- update((Button) arg0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement