widget toolbox & views

Upload: shijinbgopal

Post on 14-Apr-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Widget Toolbox & Views

    1/6

    Widget toolBox

  • 7/27/2019 Widget Toolbox & Views

    2/6

    Android supplies a toolbox of standard Views to help you

    create UIs.

    Button A standard push button.

    A button consists of text or an icon (or both text and an

    icon) that communicates what action occurs when the user

    touches it.

    Depending on whether you want a button with text, anicon, or both, you can create the button in your layout in

    three ways:

    With text, using button class

  • 7/27/2019 Widget Toolbox & Views

    3/6

    With an icon using ImageButton class

  • 7/27/2019 Widget Toolbox & Views

    4/6

    Within the Activity that hosts this layout, the

    following method handles the click event: /** Called when the user touches the button */

    publicvoid sendMessage(View view){

    // Do something in response to button click

    }

    The method you declare in the android:onClick attribute must have asignature exactly as shown above. Specifically, the method must:

    Be public

    Return void

    Define a view as its only parameter (this will be the view that was

    clicked)

    http://developer.android.com/reference/android/app/Activity.htmlhttp://developer.android.com/reference/android/app/Activity.html
  • 7/27/2019 Widget Toolbox & Views

    5/6

    Using an OnClickListener can declare the click event handler pragmatically rather than in an XML

    layout. This might be necessary if you instantiate the Button at runtime or

    you need to declare the click behavior in a Fragmentsubclass.

    To declare the event handler programmatically, createan View.OnClickListener object and assign it to the button by

    calling setOnClickListener(View.OnClickListener)

    Eg

    Button button =

    (Button)findViewById(R.id.button_send);

    button.setOnClickListener(newView.OnClickListener()

    {

    publicvoid onClick(View v){

    // Do something in response to button click}

    });

    http://developer.android.com/reference/android/widget/Button.htmlhttp://developer.android.com/reference/android/app/Fragment.htmlhttp://developer.android.com/reference/android/view/View.OnClickListener.htmlhttp://developer.android.com/reference/android/view/View.htmlhttp://developer.android.com/reference/android/view/View.htmlhttp://developer.android.com/reference/android/view/View.OnClickListener.htmlhttp://developer.android.com/reference/android/app/Fragment.htmlhttp://developer.android.com/reference/android/widget/Button.html
  • 7/27/2019 Widget Toolbox & Views

    6/6

    TextView A standard read-only text label that

    supports multiline display, string formatting,and

    automatic word wrapping.

    Eg

    EditText An editable text entry box that accepts

    multiline entry, word-wrapping and hint text.