ClassCastException: android.inputmethodservice.KeyboardView no se puede convertir a com.support.mukhtar.simplekeyboard.CustomKeyboardView android

Tengo la class SimpleIME.kt para implementar InputMethodEditor simple y hacer mi keyboard personalizado en Android:

class SimpleIME : InputMethodService(), OnKeyboardActionListener { private var kv: CustomKeyboardView? = null private var keyboard: Keyboard? = null companion object{ const val TAG :String = "myLogs" } private var caps = false override fun onCreateInputView(): View? { kv = layoutInflater.inflate(R.layout.keyboard, null) as CustomKeyboardView keyboard = Keyboard(this, R.xml.qwerty) kv!!.keyboard = keyboard kv!!.setOnKeyboardActionListener(this) Log.d(TAG,"onCreateInputView") return kv } ... } 

y mi class CustomKeuboardView como a continuación:

 class CustomKeyboardView : KeyboardView { constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) override fun onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent?): Boolean { return super.onKeyMultiple(keyCode, repeatCount, event) } override fun onTouchEvent(me: MotionEvent?): Boolean { Log.d(TAG,"onTouchEvent "+me.toString()) return super.onTouchEvent(me) } } 

arroja classCastException de la siguiente manera:

  java.lang.ClassCastException: android.inputmethodservice.KeyboardView cannot be cast to com.support.mukhtar.simplekeyboard.CustomKeyboardView at com.support.mukhtar.simplekeyboard.SimpleIME.onCreateInputView(SimpleIME.kt:30) at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1248) at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1669) at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1636) at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:497) at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:202) at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5426) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) at dalvik.system.NativeStart.main(Native Method) 

si implemento la class SimpleIME.kt de la siguiente manera:

 class SimpleIME : InputMethodService(), OnKeyboardActionListener { private var kv: KeyboardView? = null private var keyboard: Keyboard? = null companion object{ const val TAG :String = "myLogs" } private var caps = false override fun onCreateInputView(): View? { kv = layoutInflater.inflate(R.layout.keyboard, null) as KeyboardView keyboard = Keyboard(this, R.xml.qwerty) kv!!.keyboard = keyboard kv!!.setOnKeyboardActionListener(this) Log.d(TAG,"onCreateInputView") return kv } ... } 

funciona bien, pero necesito implementar onTouchEvent en KeyboardView para manejar múltiples clics, así que creo que es necesario implementar CustomKeyboardView Class; Hay un ejemplo de CustomKeyboardView escrito en java: https://github.com/blackcj/AndroidCustomKeyboard.git Por favor ayuda

mi pregunta no es la misma: java.lang.ClassCastException: android.inputmethodservice.KeyboardView no se puede convertir a android.view.ViewGroup

porque hay un problema con layout.xml pero no tengo ningún problema porque funciona si uso KeyboardView como se muestra antes

mi file layout.keyboard.xml:

 <?xml version="1.0" encoding="UTF-8"?> <android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/keyboard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#3Aad1a" android:keyPreviewLayout ="@layout/preview" />