#if Java
Public class MyWebView extends WebView {
@Override
Public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
Return new BaseInputConnection(this, False); //this Is needed For #dispatchKeyEvent() to be notified.
}
@Override
Public boolean dispatchKeyEvent(KeyEvent event) {
boolean dispatchFirst = super.dispatchKeyEvent(event);
// Listening here For whatever key events you need
If (event.getAction() == KeyEvent.ACTION_UP)
switch (event.getKeyCode()) {
Case KeyEvent.KEYCODE_SPACE:
Case KeyEvent.KEYCODE_ENTER:
// e.g. get space And enter events here
break;
}
Return dispatchFirst;
}
}
#end if
It's probably a different error. The correct class name is WebView, case is important in Java, and you probably need the full class name android.webkit.WebView and even then I think this is a little too ambitious for inline Java.I have now tried lower case... same mistake.
i don´t know. I never used Webview much.is this possible with the above mentioned functions ?
https://stackoverflow.com/questions/11429878/read-keyboard-events-in-android-webview
Public is LOWERCASED in the Code in the link!Read Keyboard events in Android WebView
I'm trying to listen to key events in android web view. Example when user is filling a form, I should receive the key events. This is my WebView code public class MyWebView extends WebView impleme...stackoverflow.com
#if Java
public class MyWebView extends android.webkit.WebView {
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new BaseInputConnection(this, false); //this Is needed For #dispatchKeyEvent() to be notified.
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean dispatchFirst = super.dispatchKeyEvent(event);
// Listening here For whatever key events you need
if (event.getAction() == KeyEvent.ACTION_UP)
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_SPACE:
case KeyEvent.KEYCODE_ENTER:
// e.g. get space And enter events here
break;
}
return dispatchFirst;
}
}
#end if
Even if you could get it to compile that Java code by itself is not sufficient to do what you want. You might be able to define a derived class but you still need an instance of it to use it. I'm afraid that you require a better understanding of Java than you seem to have to implement this.probably the function is no longer available
If WebView was a real View then it would be no trouble. However WebView is not designed to be a local View but as a display mechanism for a remote server which is why you cannot interact with it as if it were a standard View. I don't do webby stuff so I can't really advise, and I don't know how much under your control is whatever you are viewing in the WebView. In fact is WebView the right sort of view for what you want to achieve or is there another alternative that can display HTML or rich text?catching a few characters from a view