In my app, I have an edit text which, when pressed, sets an int
value to "1". Obviously, when you press the edit text, a keyboard pops up. The keyboard is dismissed by pressing back, and I have used the following code...
@Override
public void onBackPressed() {
if (editingText == 1) {
editingText = 0;
setUnit();
}
Log.d("Back pressed", "Back was pressed :)");
super.onBackPressed();
}
... to change the value back. setUnit()
then changes the value of a TextView
H depending on the contents of the EditText
. However, as I have seen by using the logs, this method is only called when the user backs out of the entire activity, and not when the user backs out of the keyboard.
Is there any way to detect "back" presses when the keyboard is displayed? Or, alternatively, is it possible to change a string's value to match the value of the edit text in real-time? All help appreciated.