i have an activity with a viewpager
and 4 fragments
as pages.
inside one of the fragment i need to handle back button press, so i do that this way:
public void setBackButtonAction(final View view)
{
//view is root view of fragment
view.setFocusableInTouchMode(true);
view.setOnKeyListener(new View.OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK)
{
if (currentView == VIEW_MODE_ALL_CAT)
{
return false;
}
else if (currentView == VIEW_MODE_THIS_CAT)
{
currentView = VIEW_MODE_ALL_CAT;
// do something
return true;
}
}
return false;
}
});
}
so far so good, this works as expected.
and i have a EditText
inside this fragment, and i need to connect it to an adapter for filtering result, i do that this way:
public void setSearchFilterListener()
{
searchFilter.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
mAdapter.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s)
{
}
});
}
this works also as expected.
BUT if i use this EditText
, and then pressing the back button, my code for handling back button wont call at all.
what just happened? if i open the app and press the back button the code for handling back is being called, But if i use
EditText
and then pressing the back Button, the code for handling back wont call at all.
anybody know whats going on here?
any help would be appreciated.