Listeners for various Android components

Source: Internet
Author: User

"One" Spinner (rotation button or drop-down list): Set the listener to: Setonitemselectedlistener
Set the animation effect to: Setontouchlistener
Adapter is: Arrayadapter
"II" DatePicker (   a calendar layout view of a selected month and day):  public void init (int, int monthofyear, int dayofmonth, & nbsp;                                                                                                                                                                    Datepicker.ondatechangedlistener OnDateChangedListener) Initializes the state.
(Translator's note: date of initial date)

Parameters

                             year          Initial year (translator Note: Note Using the new Date () to initialize the years, requires +1900, as follows: Date.getyear () +                                                                                                                         1900)

Monthofyear initial month.

DayOfMonth initial date.

Ondatechangedlistener event listener that notifies the user when the date changes, can be empty (null).
Timepicker: (Used to select a view of the time of day, support 24-hour and morning/afternoon mode.) ) Set the listener to: Setontimechangedlistener
"Four" ImageView: (Displays any image, the example is marked.) ImageView classes can load images from various sources (such as resources or picture libraries)
The Setup listener is: Setonclicklistener

"Five" button: (on behalf of a normal button assembly) set the listener as: Setonclicklistener
"VI" in the relativelayout layout to let the component horizontally centered display method:
                                                            android:layout_width= "Wrap_content"   and                                                                                         Android:layout_centerhorizontal= "true"

UI controls do not have android:layout_gravity properties in relative layouts
The android:gravity value refers to the content of the UI control itself, and the android:layout_gravity value is relative to the location of the parent layout.


The common layout in Android is LinearLayout and Relativelayout

When developing an application, it is recommended to use relative layout, because it is better to adapt to multi-screen size, so that UI controls can be conveniently centered, pinned, etc.
The difference between android:gravity and android:layout_gravity:
There are many similar android:gravity and Android:layout_gravity properties in Android, very similar. The beginning of the total use of mixed, and later checked. It turns out that the "layout" attribute in front of "android:layout_gravity" is actually relative to its parent element, stating the position of the element in the parent element. And like Android:gravity, there is no "layout" in front of the property, is the element itself said!
Gravity This English word is the meaning of the center of gravity, here means the docking position.

The difference between android:layout_gravity and android:gravity

As can be seen from the name, Android:gravity is the element itself, the text of the element itself is displayed in what place by this property setting, but not set by default is on the left.

Android:layout_gravity is relative to its parent element, stating where the element appears in the parent element.

For example, button:android:layout_gravity represents the position of the button on the interface. The android:gravity represents the position of the word on the button on the button.

Optional values

The optional values for these two properties are: Top, bottom, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_vertical.

And these properties are available in multiple selections, with the "|" Separate.

The default value for this is: Gravity.left

Simple memory: Horizontal are the horizontal direction of operation, that is, horizontal, vertical are the vertical direction of speculation, that is, vertical.


Questions about when LinearLayout will take effect


For LinearLayout

When android:orientation= "vertical", only the horizontal setting will work, and the vertical setting will not work. That is: The left,right,center_horizontal is in force.

When android:orientation= "Horizontal", only the vertical setting will work, and the horizontal setting will not work. That is: The top,bottom,center_vertical is in force.
The "Seven" GridView (a scrollable view component that can display multiple entries on a plane): Set listener: Setonitemclicklistener
"Eight" ListView (a list view viewed through the vertical scroll bar). Setup Listener: Setonitemclicklistener
"IX" Radiogroup (this class is used to create a group of radio buttons that are mutually exclusive to a set of buttons, and selecting a button in the same radio button group cancels the selection of other checked buttons in that group.) ) Set Listener: Oncheckedchangelistener
"Ten" slidingdrawer (sliding drawer) hides the contents of the screen and allows the user to drag a handle to show hidden content

Setup Listener: Setondraweropenlistener,setondrawercloselistener

"11" Android in the Almighty Baseadapter (spinner,listview,gridview,gallery) use!

"12" Ratingbar use star type to display grade evaluation Setonratingbarchangelistener

13 Note: Creating an. xml file is a letter that must be 0-9 or a-Z (must be lowercase) uppercase.

14 Separate Views Groups: WebView (Page view), Spinner (rotate button), Textswitcher (text switcher),
Imageswitcher (Image switcher).

Listeners for various Android components

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.