I'm attempting to implement a custom keyboard in my app and I need to use it during a login dialog prompt.
I've attempted to implement the example found here:
http://www.fampennings.nl/maarten/android/09keyboard/index.htm
However I'm getting an error in my code when I attempt to implement it on the line:
mCustomKeyboard= new CustomKeyboard(this, R.id.keyboardview, R.xml.hexkbd );
Stating that "The constructor CustomKeyboard(LoginDialog, int, int) is undefined LoginDialog.java"
I've tried changing the constructor from:
public CustomKeyboard(Activity host, int viewid, int layoutid) {
mHostActivity= host;
to
public CustomKeyboard(LoginDialog loginDialog, int viewid, int layoutid) {
mHostActivity= loginDialog;
but it causes a domino effect of other issues in the code so I'm thinking there is a better way of implementing this constructor.
public class LoginDialog extends DialogFragment implements
ActionCompletedListener {
private View view;
private String whichActivity = "";
private TextView error;
CustomKeyboard mCustomKeyboard;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(getActivity(), R.style.HoloDarkDialog));
LayoutInflater inflater = getActivity().getLayoutInflater();
view = inflater.inflate(R.layout.login, null);
mCustomKeyboard = new CustomKeyboard(this, R.id.keyboardview,
R.xml.hexkbd);
public CustomKeyboard(Activity host, int viewid, int layoutid) {
mHostActivity= host;
mKeyboardView= (KeyboardView)mHostActivity.findViewById(viewid);
mKeyboardView.setKeyboard(new Keyboard(mHostActivity, layoutid));
mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview balloons
mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
// Hide the standard keyboard initially
mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
P.S.
Any suggestions are GREATLY appreciated... and additional information/source can/will be provided promptly by request.
Full source can be found here:
http://www.fampennings.nl/maarten/android/09keyboard/index.htm
The problem here is that by supplying this
at the constructor, you are pointing to the LoginDialog
which was inherited from DialogFragment
, which is subclass of Fragment
, while constructor expects Activity
or any of it's subclasses. I don't know the full code, but if you need to supply Activity
to constructor, you can use HostingActivity.this
. If you want to work with this constructor:
public CustomKeyboard(LoginDialog loginDialog, int viewid, int layoutid)
you can get hosting activity by calling loginDialog.getActivity()
and you can get corresponding view with loginDialog.getView()