This is what happens:
Activity A and B have an EditText
and they both have IME_SEARCH
. The input is done only via soft keyboard on a SAMSUNG tablet.
On Activity A I can use the EditText
without problems. The thing is that on Activity B I can't erase text with backspace after I hit 'space' or whenever I use a word from the suggestions. It behaves like there wasn't text there anymore. If I type new characters, I can erase them up to the space.
Important points:
EditTexts
are identicalIME_SEARCH
processing (via setOnEditorActionListener
) is identicalTextWatcher
of both are also identicalandroid:configChanges="keyboardHidden|keyboard|orientation" android:windowSoftInputMode="stateAlwaysHidden|adjustUnspecified"
I set a breakpoint on the method beforeTextChanged
of both TextWatcher
. I inserted a 'space' and hit 'backspace'. On the Edittext
of activity A, the method is triggered but on activity B's it is not triggered. I can't see the reason for this to happen since the properties of both Edittext
are configured identically.
I also tried removing the IME
option but the behavior kept the same.
Does anyone know what could be happening?
EDIT 1:
searchTxt.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) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
btnClear.setVisibility(View.GONE);
} else{
btnClear.setVisibility(View.VISIBLE);
}
}
});
searchTxt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
buildGrid();
return true;
}
return false;
}
});
EDIT 2: The layout hierarchy is as following.
<LinearLayout
... >
<include layout="@layout/title_bar" />
<RelativeLayout
...>
<EditText
...>
The problem was that, for some reason, the Activity B was overriding dispatchKeyEvent()
and always returning true
. Removing it solved the problem.