Tuesday, 19 April 2011

How To Exit The Application Using In Button

Open the layout XML and add the button element.Assign an ID with the “@+id” operator.The + tells Android to generate an ID for this element so that you can reference it in your Java files.This is an example.Your layout and text elements will probably be very different. In this example case, the ID of the button is “close”.

<Button android:id="@+id/close"
    android:text="@string/title_close" />

//Open the activity class.  Add a class property to hold a reference to the button.
  private Button closeButton;

//Now, in the onCreate method, attach a listener to the click event for the button. This example will call //“finish()” on the activity, the Android analog of clicking the close button on a window.

 this.closeButton = (Button)this.findViewById(;
        this.closeButton.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {


No comments:

Post a Comment