Thursday, December 27, 2012

Android and me : Button Action

  • use the Button onClick attr to declare the name of the action method
  • open the Activity that displays the layout with the Button
  • add a method with a name matching onClick attr value
  • make sure the method takes in a single View as a parameter
in /res/layout
 <Button
        android:text="@string/love_button_text"
        android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onLoveButtonClicked"
         />
in java
public void onLoveButtonClicked(View view){
      //action
    }

No comments:

Post a Comment