Who to capture the click of any button?
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(WHKConversorActivity.this, "Hello World", Toast.LENGTH_SHORT).show();
}
});
this is a click on button1 but i need an function for all buttons :-/ .
Example in javascript:
$('button').click(function(){
alert($(this).val());
});
Thanks 🙂
If you want all your buttons to do exactly the same thing (which is unlikely) you could bind the same click listener to each button. Eg:
Or if you want a each button to do something different, but still need some sort of reapeated function for each, you could put that part of the code in a seperate method and reference it in every click listener