I'm Android newbie. I've done some of the tutorials, explored the SDK softkeyboard example and the "smallkeyboard" class that Chris Boyle shared. Now I'm trying to test a simple KeyboardView that later I will make do something. I can't seem to get it to to work. The emulator says the app stopped unexpectedly (before a keyboard is displayed) and forces close. Can anyone see what I'm missing?
And this tells you what's wrong with the class: Android doesn't know it ("can't find it", in Java terms). And indeed, the android.view package has no such class. There is a class with a similar name in a different package, though, which I assume you meant. Figuring out the right package and the right class name is left as an exercise to the reader :-)
Joined: Feb 12, 2011
So Let's see,
I know when I included the class it was with "import android.inputmethodservice.KeyboardView;"
when I create it with "myKeyboardView = (KeyboardView)findViewById(R.id.myKeyboardViewXML); "
I must be indirectly trying to cast a view class result as an inputmethodservice.keyboardView object.
Am I close?
are there other/better ways to construct the keyboardview object?
I'm working towards a keyboard that is always up on the screen and used as an input. I don't want to create a keyboard service.
I was basing my approach on the following advice I found on some other forums.
Keyboard/KeyboardView is just a view. It is often used for writing the UI
of an input method, but you can use it to write any UI.
To use it in your app, you just need to incorporate it into your UI
appropriately. No just throwing it into your XML will probably not work.
If you want to show it and hide it, you will need to decide how you want
this to interact with the rest of the UI. For example you could put it in a
Dialog that you set up without a frame (there are API demos showing how to
customize Dialog visuals), and make a window animation to have it slide up
from the bottom of the screen when it is displayed. What exactly to do with
the view is up to you.
Joined: Mar 22, 2005
The problem isn't with the code, or you'd be getting a compilation error. The problem is in one of the XML files.
I have no particular knowledge of keyboards or keyboard layouts, so I can't help with the actual issue you're trying to address.
Joined: Feb 12, 2011
You've helped some and at least I'm moving forward; I'll explore the XML more deeply. Meanwhile if anyone else has some tips I'm all ears!
I had a very similar problem. I was using inflate() to load the KeyboardView, because other methods did not seem to be working. I was getting an error in the logcat output file: android.view.InflateException: Binary XML file line #2: Error inflating class KeyboardView. After some more research in the Android documentation, I found a section on custom views. There I found an example with a class LabelView. The XML resource file contained a fully qualified name for the class. I tried this with KeyboardView, entering <android.inputmethodservice.KeyboardView> in my layout file. My code now loaded without error!