Handling Image Button Events

You handle ImageButton events such as clicks exactly the same way as you would with any View control—by using click listeners. For the avatar ImageButton control, you want to handle clicks and long-clicks.

Handling Clicks with setOnClickListener

To listen and handle when a user clicks on the avatar ImageButton control, you must implement the View.OnClickListener() method:

avatarButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {

// TODO: Launch the Camera and Save the Photo as the Avatar

This should look familiar because you've already implemented a number of listeners for Button controls.

Was this article helpful?

0 0

Post a comment