Difference between focusable and focusableInTouchMode?
Asked Answered
A

4

102

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.

Allergist answered 11/6, 2014 at 6:25 Comment(3)
#8656392Deepfreeze
android-developers.blogspot.fi/2008/12/touch-mode.html Here Romain says that using focusableInTouchMode should be avoided unless you are developing a gameCalx
if focusable = false - you can't focus this view, even EditText if you push Next button on keyboard.Ostracon
G
87

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.

Gavingavini answered 11/6, 2014 at 6:43 Comment(0)
M
13

Give some example and explain them in detail

I'll give you my own experience:

I had a Google TV application which had an activity with a great deal of ImageButtons.

I wanted the ImageButtons to be selectable.

So if a person clicks on them with mouse or remote controller, they become selected only (Highlighted in my case). Then if the user presses the selected ImageButton, the action triggers. This exact behaviour was achieved through enabling the focusableInTouchMode property through the XML layout.

All I had to do was to set an ordinary onClickListener for the ImageButtons and voila!

I haven't checked my application on handset but I guess it would deliver familiar result.

EDIT

When?

I've told you a use case I have tested: When you want your Button's onClickListener to trigger action on your second click, after you have first clicked and selected the Button.

I Used the first click to gain "focus" and display a Zoom-In scale Up animation on my button.

How?

Just set the button's property focusableInTouchMode to true in your XML layout file.

Mitchellmitchem answered 11/6, 2014 at 6:54 Comment(1)
when to use them. how they are helpfulAllergist
C
7

Focused is a state for view and generally focus can be changed with trackball and dpad. Your view can have different background when state is focused.

Focusable in touch mode allows view to gain focus when user is touching the view, good example of this kind of component is EditText.

With Button or any clickable component pressed state is usually what you are interested in.

Calx answered 11/6, 2014 at 6:47 Comment(1)
"With Button or any clickable component you should be focusing on pressed state instead." what? the rest of the answer +1Luannaluanne
A
3

Users can interact with their devices by using hardware keys or buttons, or by touching the screen. Touching the screen puts the device into touch mode. The user can then interact with it by touching the on-screen virtual buttons, images, etc.

To check if the device is in touch mode, call the View class's isInTouchMode() method.

Astrakhan answered 20/7, 2015 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.