Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which view is focused?

Tags:

android

I need to find out if any view is focused inside an Activity and what view it is. How to do this?

like image 416
Fixpoint Avatar asked Mar 18 '11 12:03

Fixpoint


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.

How do I know if Edittext is focused?

You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus. This goes in your activity or fragment or wherever you have the EditTexts.


1 Answers

Call getCurrentFocus() on the Activity.

like image 81
Karan Avatar answered Sep 28 '22 15:09

Karan