Solution 1:

   ImageButton ImageView01 = (ImageButton)findViewById(R.id.ImageView01);
   ImageView01.setOnClickListener(new OnClickListener() {
	 public void onClick(View v) {

	 }

   });

Solution 2:


// Create an anonymous implementation of OnClickListener
private OnClickListener mCorkyListener = new OnClickListener() {
public void onClick(View v) {
// do something when the button is clicked
}
};

protected void onCreate(Bundle savedValues) {
...
// Capture our button from layout
ImageButton ImageView01 = (ImageButton)findViewById(R.id.ImageView01);
// Register the onClick listener with the implementation above
ImageView01.setOnClickListener(mCorkyListener);
...
}

Solution 3:

public class ExampleActivity extends Activity implements OnClickListener {
    protected void onCreate(Bundle savedValues) {
        ...
        Button button = (Button)findViewById(R.id.corky);
        button.setOnClickListener(this);
    }

    // Implement the OnClickListener callback
    public void onClick(View v) {
      // do something when the button is clicked
    }
    ...
}

reference:

http://developer.android.com/guide/topics/ui/ui-events.html

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply