Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Button OnClickListener
package blog.topherpedersen.uselesscameraapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button myButton = findViewById(R.id.my_button);
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Button Clicked!", Toast.LENGTH_LONG).show();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment