How to use the android button

Source: Internet
Author: User

    1. Package Com.hangsheng.button;
    2. import android.app.Activity;
    3. import Android.os.Bundle;
    4. import Android.view.View;
    5. import Android.widget.Button;
    6. Public class ex07_widgetbuttonactivity extends Activity {
    7. /** called when the activity is first created. * /
    8. @Override
    9. Public void onCreate (Bundle savedinstancestate) {
    10. Super. OnCreate (savedinstancestate);
    11. Setcontentview (R.layout.main); //Associated layout template file Main.xml
    12. Find_and_modify_button (); //Call member function Find_and_modity_button
    13. }
    14. private void Find_and_modify_button () {
    15. Button button = (button) Findviewbyid (R.id.button); //Instantiate a button object with a resource with ID as button in the resource
    16. Button.setonclicklistener (Button_listener); //Set the listener for the object button
    17. };
    18. Private button.onclicklistener button_listener =new Button.onclicklistener () { // member button Listener Object
    19. @Override
    20. Public void OnClick (View v) { //button event
    21. //TODO auto-generated method stub
    22. Settitle ("button was clicked");
    23. }
    24. };
    25. }

Layout template file Main.xml:

  1. <? XML version="1.0" encoding="Utf-8" ?>
  2. <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. Android:text="@string/hello" />
  10. <Button
  11. android:id="@+id/button"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. Android:text="This is button" />
  15. </linearlayout>

How to use the android button

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.