Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between hasFocus() and isFocused() in android?

Tags:

java

android

I understand the difference among focused, selected and pressed. But I don't understand the difference between hasFocus() and isFocused(). I checked the description, both descriptions say almost the same thing. Can anyone please explain this to me?

like image 483
Bibaswann Bandyopadhyay Avatar asked Oct 08 '15 17:10

Bibaswann Bandyopadhyay


People also ask

How do you know if a view is focused?

The View. isFocused() method tells whether the view in question is focused or not. Or else, you can compare your views by id. @CGR Well, isFocused() is the preferred way to go here.

What is focusable Android?

Focusable means that it can gain the focus from an input device like a keyboard. Input devices like keyboards cannot decide which view to send its input events to based on the inputs itself, so they send them to the view that has focus.


1 Answers

hasFocus() is different from isFocused(). hasFocus() == true means that the View or one of its descendants is focused. If you look closely, there's a chain of hasFocused Views till you reach the View that isFocused.

like image 177
Rajan Kali Avatar answered Oct 21 '22 18:10

Rajan Kali