Last active
March 1, 2018 08:55
-
-
Save bluemyria/9d9ba0b83f4d0e37028266ed1a0376dd to your computer and use it in GitHub Desktop.
Android - 001 - Click Listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
// Die zu verwendenden Controls werden hier deklariert | |
private TextView lbl; | |
private Button btn; | |
private int zaehler; | |
private class MyOCL implements View.OnClickListener { | |
@Override | |
public void onClick(View view) { | |
zaehler++; | |
lbl.setText("Hallo Maria! Zähler: " + zaehler); | |
} | |
} | |
@Override | |
// Wird aufgerufen wenn man eine Activity startet | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
zaehler = 0; | |
lbl = findViewById(R.id.lbl); | |
btn = findViewById(R.id.btn); | |
lbl.setText("Hallo Maria!"); | |
btn.setOnClickListener(new MyOCL()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment