Skip to content Skip to sidebar Skip to footer

Java.lang.classcastexception: Android.inputmethodservice.keyboardview Cannot Be Cast To Android.view.viewgroup

I am getting this error while trying to use other layouts inside keyboard view as in my xml file. I don't want my keyboard layout to have rows and keys as in normal keyboard instea

Solution 1:

You get the error because KeyboardView extends View , which cannot contain children like ViewGroup.

In order to make it work you need to create a separate layout file with your keyboard layout and then add it to the KeyboardView like this:

<android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    ...
    android:keyPreviewLayout ="@layout/your_keyboard_layout">

For full tutorial how to customize keyboard : https://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615

Post a Comment for "Java.lang.classcastexception: Android.inputmethodservice.keyboardview Cannot Be Cast To Android.view.viewgroup"