How do you know which gaze is focused?

I need to find out if any view inside the Activity is focused and what kind of view it is. How to do it?

+49
android
Mar 18 '11 at 12:51
source share
3 answers

Call getCurrentFocus() in the Activity.

+69
Mar 18 '11 at 12:55
source share

From the source of activity:

  /** * Calls {@link android.view.Window#getCurrentFocus} on the * Window of this Activity to return the currently focused view. * * @return View The current View with focus or null. * * @see #getWindow * @see android.view.Window#getCurrentFocus */ public View getCurrentFocus() { return mWindow != null ? mWindow.getCurrentFocus() : null; } 
+9
Jan 10 '14 at 11:50
source share

for any reason, the getCurrentFocus () method is not available; probably it is already outdated, here is a working alternative:

 View focusedView = (View) yourParentView.getFocusedChild(); 
+4
03 Sep '14 at 6:10
source share



All Articles