Monitoring of the spinner

Source: Internet
Author: User

Neither setonitemclicklistener nor setonclicklistener can be used to listen to the spinner. Otherwise, an error occurs.

Setonlongclicklistener can be used to listen to the long-pressed events of a spinner. It can only listen to the long-pressed events of a spinner. It seems that it is basically useless.

Setontouchlistener can be used to listen to the touch events of the spinner control. Note that a quick touch can trigger this event several times.

 

Setonhierarchychangelistener is used to listen to the view changes displayed on the spinner. You need to override two methods. This listener will be triggered when you click "Spinner" to select an item. If you select a different item, the onchildviewremoved ----- onchildviewadded ----- onchildviewremoved will be executed. When the selected item does not change. Run onchildviewremoved --- onchildviewadded.

Use method spinner. removeallviewsinlayout () can clear the information displayed on the spinner control and trigger the onchildviewremoved method of setonhierarchychangelistener. After clearing the information displayed on the spinner control, click the "select item" control, if the selected item is the same as the previously displayed item, run onchildviewadded --- onchildviewremoved --- onchildviewadded, and the information displayed on the spinner is changed to 0th pieces of information. If it is not the same item, onchildviewadded --- onchildviewremoved --- onchildviewadded --- onchildviewremoved.

Setonitemselectedlistener listens to the select event of the item option in the spinner and overwrites the two methods. The onitemselected method is triggered when the selection is made. However, if the selected item and the item before the selection are the same, this method will not be triggered. The second method is onnothingselected. I have tested it many times and cannot trigger this method. I don't know under what circumstances to trigger it. If anyone knows, ask me. Thank you!

I tried to write a listener to the items of the spinner (I used the baseadapter to listen to the view to be returned in the getview method). I found that the setonlongclicklistener AND THE setonclicklistener listeners can listen to items of the spinner, however, after listening, the setonitemselectedlistener listener of the spinner is overwritten, and the selected item can be clicked. That is to say, the item and the spinner control are floating in the same view, clicking the item in the center of the spinner will not trigger the click of the spinner, but will trigger the click of the item.

However, if setontouchlistener is used to listen to items, it will not overwrite the setonitemselectedlistener listener. However, when you click the spinner, you must note that if the clicked area is in the item area, the setontouchlistener listener will be triggered, if you click outside the green area, setontouchlistener is not triggered. (For example ).

After learning, it is found that the baseadapter subclass of the spinneradapter has a method of getdropdownview, which is used to display all the items pulled out, while the getview method is used to display an item on the spinner, the default return value of getdropdownview is the return value of getview. This means that the Code originally written in getview can be written in getdropdownview, And the listener can also write it here. getview retains the code other than the listener, in this way, you can only use setontouchlistener to listen for items that are not triggered when you click the spinner, because the listener for long and short presses will overwrite the setonitemselectedlistener listener.

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.