Why Android your Onfocuschangelistener and android:state_hovered don't work

Source: Internet
Author: User

First publish my test results, Android inside in addition to edittext to it after binding Onfocuschangelistener, will return true, the other components are not responding, unless you call Requestfocus, But even if you call the Requestfocus after, Onfocuschangelistener will still give you return false, many online posts on the focus of the problem are specious, so I decided to find the answer from the source code, Looking for a long day only from the TextView found some clues:

@Override      Public Event ) {        intevent. getactionmasked ();         if null) Meditor.ontouchevent (event);

And the Meditor statement is here:

Private Editor Meditor;

And this editor class in the end is what thing, the source of clues is interrupted, but at least a point, EditText (EditText than the general TextView one editor) of the processing logic with the general TextView is not the same, And it's probably written about the logic that changed focus.

Also tested two occasions, one is a page only a edittext, to it binding Onfocuschangelistener, click on the other areas of the page, Focuslistener is not any reaction; the second occasion, Multiple edittext in turn, Onfocuschangelistener magically played a role.

Finally, I found a reasonable answer in a foreign forum:

In fact, think carefully, before writing selector time android:state_hovered This property set up is also not work, later found out that the foreigner's argument is aimed at the mouse, and then himself does not superstitious, to the plate inserted mouse, it is really working, This focus is the same reason, but based on the particularity of EditText (EditText is the cursor), Android gave EditText special case, although the source is not found, but we can guess: meditor.ontouchevent ( Event) is the logic to change focus.

The last classmate's point of view I very much agree with, have to echo a sentence: This nappy guy comment was just proof to me that the Android API was complete garbage!

Why Android your onfocuschangelistener and android:state_hovered don't work

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.