I built the listener using this answer and my task LoopingTask, thanks by the way.
Very easy to implement using SoftKeyboardListener from Viper Pack android library.
Just install the library then add this to your code :
Lava.app.addSoftKeyboardListener(context, new Lava.SoftKeyboardListener() {
@Override
public void onSoftKeyboardShow(EditText focusedview) {
// when shows
}
@Override
public void onSoftKeyboardHide(EditText focusedview) {
// when hides
}
});
Dislaimer : adding a lot of listeners may slow/crash your app, you still can use
Lava.app.removeSoftKeyboardListeners()
to remove all the previous listeners.
Dislaimer 2 : creating a SoftKeyboardListener directly in activity
onCreate
will add a new one every time the activity resume itself, so make sure to limit that using a boolean :
boolean isListenerAdded;
...
@Override
public void onCreate(Bundle sis) {
super.onCreate(sis);
...
if (!isListenerAdded) {
isListenerAdded = true;
// create your listener here
}
...
}
...
Or just remove all the previous ones :
...
@Override
public void onCreate(Bundle sis) {
super.onCreate(sis);
...
Lava.app.removeSoftKeyboardListeners();
// create your listener here
...
}
...
Lava.app.removeSoftKeyboardListeners()
removes all previous SoftKeyboardListeners.
trying to detect the virtual keyboard height in Android.
– HoaryX
andY
location falls on/over the keyboard =>SecurityException
=> decrementY
and try again => until no exception is thrown => currentY
value is the keyboard height. 2. if the keyboard is not open => noSecurityException
. – KathiekathleenSecurityException
is thrown => keyboard is open. Else, keyboard is closed. – KathiekathleenEditText
not otherEditText
. How I can distinguish this ? – Hoarylistener
. I'm quite sure that android doesn't provide any. Probably, someone else can offer another hack. – Kathiekathleen