package com.MySample; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class MySample extends Activity { // put instance variables here ImageButton myImageButton; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // we will use the main.xml file to create all of our // UI objects and display them on the screen setContentView(R.layout.main); setTitle("Title under status bar"); // put other initialization stuff here // references to your UI objects would get initialized here // All objects declared in the layout file main.xml // are created by the Activity setContentView(R.layout.main); // you call the findViewById method to get their memory location myImageButton = (ImageButton) findViewById(R.id.ImageButton01); } // put other methods here // onButtonClick method // the name of the method was defined in the xml file public void onButtonClick(View v) { // do whatever // v will hold the address of the Button } }