Question

Is there a way to programmatically deselect/wipe whatever the user has selected with the trackball/trackpad?

When I hit the back button on an Activity, the Activity it falls back to has a button that is selected as if the user had used the trackball/pad. I'm not sure what is selected on the previous Activity, but obviously something is. I'd like to programmatically wipe any selection just before the Activity finishes.

Was it helpful?

Solution

Looking through the JavaDoc for View I see a number of focus-related functions.

void clearFocus(); // drop focus from this view.
View findFocus(); // finds a view that is a child of this view that has focus, if any
View focusSearch(int dir); // finds the next view that can take focus in the given direction
void requestFocus

Sounds like findFocus().clearFocus() should do the trick (unless findFocus happens to return null)... you just need a handle to the other activity's View... which shouldn't be too hard if it's your code, or Non Trivial if it isn't.

If it IS your code, it seems like you could just add a clearFocus() to the button's onClickHandler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top