1

I have an activity with 2 types of views EditText and CustomEditText my custom edit text has a onFocusChanged()method and I can know when the view gains and looses focus, but I would like to know which view gains focus in order to perform different actions, is possible to know from the onFocusChanged() method which view got focus after this view looses it?

Calling getCurrentFocus() from the overwritten method in a custom view like this will return null so that will not work

@Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        if (focused ) {

        }else{
            Activity activity = (Activity) this.getContext();
            activity.getCurrentFocus();//this returns null
        }

        super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }
Westside Tony
  • 708
  • 7
  • 20
  • 1
    Call `getCurrentFocus()` on the Activity. as per [How to find out which view is focused?](http://stackoverflow.com/questions/5352209/how-to-find-out-which-view-is-focused) – MikeT Jan 11 '17 at 11:42
  • Possible duplicate of [How to find out which view is focused?](http://stackoverflow.com/questions/5352209/how-to-find-out-which-view-is-focused) – MikeT Jan 11 '17 at 11:43

0 Answers0