user1247254
user1247254

Reputation: 89

Updating Keyboard Icon

I am new to Android and Eclipse development, but not new to software development in general.

As my first real project, to get over the learning curve, I am modifying the SDK example soft keyboard to include a "macro" functionality.

The major functionality is working properly. But, I am having trouble getting the keyboard key icon to update in one of 2 situations.

I have created a function key, "Fn", that when I press followed by a letter key will insert one of my predefined strings into the edit field – like my e-mail address.

In the first situation, when I press the function key I change the icon to signify "function active". If I repeatedly press the function key, the icon changes back and forth between signifying active and inactive. This is correct.

In the second situation, I press the function key, the icon changes to signify "function active", then I press a letter key. The macro string is entered in whatever text field properly, in code I then change the "function" state to inactive and update the icon.

Using Logs I can see the code is executed to properly change the icon, but the icon does not change. It is still showing the "function active" state even though I see that the internal flag has changed to inactive and I can see that the key icon drawable was written properly to have the key show the "function inactive" state.

I have tried a whole bunch of different things – to no avail.

What is going on that prevents this key icon from updating in this situation?

Everything in the second situation seems to execute the same code as in the first situation – the case that works, repeatedly pressing the function key. I can think of one difference. When repeatedly pressing the function key, the function key has "focus". When I press the function key and then press a letter key, the letter key is the one with "focus". I don't know if this makes sense or not. I have tried looking for some kind of invalidate method, but I can't find anything.

Any hints or suggestions are very appreciated.

Thanks, Barry.

Upvotes: 1

Views: 508

Answers (1)

jsimpson
jsimpson

Reputation: 391

If i remember correctly, the softkeyboard example uses 2 different keyboard layouts and switches between them when you press it. One has "inactive", and the other has "active".

However, from my understanding, you are actually changing the physical icon without switching keyboard layouts. If this is the case, then the keyboard needs to be re-created every time. Why? When a keyboard view is created for the first time, it is reused over and over again. Even if you change the icon, it won't necessarily recreate the view.

I had this sort of problem before. Try recreating your Keyboard object - this will recreate the view as well. the function createKeyFromXml in the Keyboard class is where the "key" is actually created. If you put logs in this function, it is only called once for each key when the object is created/or showed for the first time.

Upvotes: 2

Related Questions