构造函数自定义键盘(LoginDialog, int, int) 未定义



我正在尝试在我的应用程序中实现自定义键盘,我需要在登录对话框提示期间使用它。

我试图实现这里找到的示例:

http://www.fampennings.nl/maarten/android/09keyboard/index.htm

但是,当我尝试在线实现它时,我的代码中出现错误:

mCustomKeyboard= new CustomKeyboard(this, R.id.keyboardview, R.xml.hexkbd );

声明"构造函数 CustomKeyboard(LoginDialog, int, int( 是未定义的 LoginDialog.java">

我尝试将构造函数从:

   public CustomKeyboard(Activity host, int viewid, int layoutid) {
mHostActivity= host;

 public CustomKeyboard(LoginDialog loginDialog, int viewid, int layoutid) {
        mHostActivity= loginDialog;

但它会导致代码中其他问题的多米诺骨牌效应,所以我认为有更好的方法来实现这个构造函数。

登录对话框.java

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);

自定义键盘.java

  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);
}

附言

任何建议都非常感谢...其他信息/来源可以/将应要求及时提供。

完整的来源可以在这里找到:

http://www.fampennings.nl/maarten/android/09keyboard/index.htm

这里的问题是,通过在构造函数中提供this,您指向从DialogFragment继承的LoginDialog,它是Fragment的子类,而构造函数需要Activity或其任何子类。我不知道完整的代码,但是如果您需要向构造函数提供Activity,则可以使用HostingActivity.this.如果要使用此构造函数:

public CustomKeyboard(LoginDialog loginDialog, int viewid, int layoutid)

您可以通过调用loginDialog.getActivity()来获取托管活动,也可以通过loginDialog.getView()获得相应的视图

registerEditText(int resid)

在"活动视图"中搜索"编辑文本"。

您应该将对话框视图添加到自定义键盘构造函数中,并让 registerEditText 在那里搜索 EditText

最新更新