Android Chinese API (29) -- CompoundButton

Source: Internet
Author: User

Preface

This chapter covers android. widget. CompoundButton. The translation is from derod. Thank you again! I look forward to your participation in Android API Chinese translation, contact me over140@gmail.com.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog Garden: http://www.cnblogs.com/

Android Chinese translation group: http://www.cnblogs.com/over140/

 

Body

I. Structure

    Public abstract class CompoundButton extends Button implements Checkable

 

Java. lang. Object
Android. view. View
Android. widget. TextView
Android. widget. Button
Android. widget. CompoundButton

 

Ii. Overview

A button with the selected or unselected status. The status is automatically changed when the button is pressed or clicked.

 

Iii. Public Methods

Public boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

Send an auxiliary event when building the sub-view. (Note: The Source Code shows that the selected status is set during View Construction .)

Parameters

Event

Return Value

Returns True if all events are completed.

 

Public boolean isChecked ()

(Translator's note: select or not)

 

Public void onRestoreInstanceState (Parcelable state)

Allows the view to be re-applied. Previously, onSaveInstanceState () was used to generate an internal state. This function never calls an empty state.

Parameters

The state returns the status that was previously saved by calling onSaveInstanceState.

 

Public Parcelable onSaveInstanceState ()

Allows the view to generate an internal status, which can be used to create a new instance with the same status. This status should only contain information that is not persistent or cannot be rebuilt in the future. For example, you will never store your current location on the screen, because it will re-calculate and place a new instance at the view level.

You can store some examples here: the current cursor position in a text box (but usually not the text itself, the text is usually stored in the content provider) or other persistent storage), the current selected item in a list view.

Return Value

Returns a Parcelable object that contains the current state of the view, or returns null if no State is saved. By default, null is returned.

 

Public boolean merge mclick ()

If the view defines the OnClickListener listener, call this method for execution.

Return Value

If the defined OnClickListener is called, True is returned. Otherwise, False is returned.

 

Public void setButtonDrawable (Drawable d)

Set a printable object (for example, an image) for the button background)

Parameters

D. A plotting object used as the background (for example, an image)

 

Public void setButtonDrawable (int resid)

Use the resource Id to set an image for the button background

Parameters

Resid is the resource id of the background image.

 

Public void setChecked (boolean checked)

Change the selected status of the button

Parameters

Checked true selected, false unselected

 

Public void setOnCheckedChangeListener (CompoundButton. OnCheckedChangeListener listener)

Registers a callback function executed when the button status changes.

Parameters

Function called when the listener is selected and the status changes

 

Public void toggle ()

Changes the selected status to the current status.

 

Iv. Protected Methods

Protected void drawableStateChanged ()

This method is called when the view status changes and the displayed printable status is affected.

Make sure that the parent class method is called during overload.

 

Protected int [] onCreateDrawableState (int extraSpace)

Generate a new drawing area status for the current view. This method is called by the view system when the cached image drawing area status is determined to be invalid. You can use the getDrawableState () method to retrieve the current status again.

Parameters

If extraSpace is non-zero, this is the number of extra entries that you should return in the list where you can store your status.

Return Value

Returns an array that records the status of the current drawing area in the view.

 

Protected void onDraw (Canvas canvas)

Implement your own rendering.

Parameters

Canvas draws the background on the canvas

 

Protected boolean verifyDrawable (Drawable who)

If your view subclass displays its own visualization object, it will override this method and return true to display the printable object. This operation allows animation effects during painting.

Make sure that the corresponding method of the parent class needs to be called when the slave method is rewritten.

Parameters

Drawable ). If it is the object you want to display, True is returned; otherwise, the result of calling the parent class is returned.

Return Value

Boolean returns True if the Drawable object is already displayed in the view. Otherwise, false is returned. Animation is not allowed here.

 

End

Android2.3 is about to be released, and the translation team will follow up quickly. The versions already translated or being translated will keep the original version, and the new versions will start directly from the new version.

 

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.