im having a bit troubled here. I cannot seem to understand what’s the problem here. can you guys please help me? what should I do? I copied this code from here. and tried to save the project. but im having an error and it says “The method onKeyDown(int, KeyEvent) is undefined for the type object”
I am building an app with eclipse and PhoneGap 1.3.1 with jQuery 1.2.6,
Here are the code
package com.phonegap.mobilemone;
import com.phonegap.DroidGap;
import android.view.KeyEvent;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
public class KeyBoard
{
private WebView mAppView;
private DroidGap mGap;
public KeyBoard(DroidGap gap, WebView view)
{
mAppView = view;
mGap = gap;
}
public void showKeyBoard()
{
InputMethodManager mgr = (InputMethodManager)mGap.getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(mAppView, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager)mGap.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(mAppView, 0);
}
public void hideKeyBoard()
{
InputMethodManager mgr = (InputMethodManager) mGap.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(mAppView.getWindowToken(), 0);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if (mAppView.canGoBack())
{
mAppView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
With PhoneGap, you could use the “backbutton” event and keep all of your code in JavaScript. See the example in the PhoneGap docs at http://docs.phonegap.com/en/1.4.1/phonegap_events_events.md.html#backbutton