android, Tutorial 011-1, UI, ImageButton , different kind of way to call ClickListener

August 15, 2011   ·   0 Comments


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

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon