androidfocusfocusable

Difference between focusable and focusableInTouchMode?


I want to know the actual difference between them... When should each be used, how should each be used, and in which situations is each helpful?

Give some examples and explain them in detail.


Solution

  • It is explained in the Android Developers Blog: http://android-developers.blogspot.co.at/2008/12/touch-mode.html

    The following quotes should make it clear:

    By itself, the touch mode is something very easy to understand as it simply indicates whether the last user interaction was performed with the touch screen. For example, if you are using a G1 phone, selecting a widget with the trackball will take you out of touch mode;

    ...

    In touch mode, there is no focus and no selection. Any selected item in a list of in a grid becomes unselected as soon as the user enters touch mode. Similarly, any focused widgets become unfocused when the user enters touch mode.

    ...

    Now that you know focus doesn't exist in touch mode, I must explain that it's not entirely true. Focus can exist in touch mode but in a very special way we call focusable in touch mode. This special mode was created for widgets that receive text input, like EditText or, when filtering is enabled, ListView.

    ...

    Focusable in touch mode is a property that you can set yourself either from code or XML. However, it should be used sparingly and only in very specific situations as it breaks consistency with Android normal behavior. A game is a good example of an application that can make good use of the focusable in touch mode property. MapView, if used in fullscreen as in Google Maps, is another good example of where you can use focusable in touch mode correctly.