Search code examples
androidlistviewbacksearchview

Android Back key cycling focus instead of returning to previous activity


I have this layout

enter image description here

Two SearchView widgets
One ListView

When I press the android back key the focus cycles between the filter box and the search box.
I want to go back to my previous activity, but I cannot do it, since the back key only goes from one box to the other.
How can I get the back key press event ?

this code does not even get called

@Override
public void onBackPressed() {
    setResult(Activity.RESULT_CANCELED);
    super.onBackPressed();   
}

Solution

  • The problem is definitely with the SearchView widgets and its handling of the focus/backkey.
    I changed the SearchViews to EditTexts
    I changed the QueryTextListeners to TextWatchers
    and... voila!

    Now the onBackPressed() is called and the activity can return to its previous caller.

    enter image description here