How to set selection of editText by using SendKeyEvent function of InputConnection class

by DrBrain » Thu, 30 Apr 2009 02:06:02 GMT


Sponsored Links
 I need to set selection of an editText box via InputConnection. I used
the SendKeyEvent function with the KEYCODE_DPAD_LEFT and META_SHIFT_ON
state but I've had no luck. My code is as below:

...
// I've already received hardware key event of DPAD left key as event
parameter in this function.

// Change the meta state of event parameter to META_SHIFT_ON
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
                        event.getAction(), event.getKeyCode(), 
event.getRepeatCount(),
KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE|
KeyEvent.META_SHIFT_LEFT_ON|KeyEvent.META_SHIFT_ON,
                        event.getDeviceId(), event.getScanCode());
InputConnection ic = getCurrentInputConnection();
ic.sendKeyEvent(event);

After excuting the code, there still no selection in the EditText.

Could somebody help me to resolve this ?

Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Html with ArrayAdapter<CharSequence>

Hi !
I've a problem with Android 1.5 and all the previous versions.

Simply, I have a ListView with an ArrayAdapter<CharSequence> but when
I instantiate a CharSequence with Html.fromHtml (for example "<b>Hi!
How are you?</b>") and i put this CharSequence into the ArrayAdapter
with the method add(), if the version of Android if lower than 1.6,
the ListView is colorless. I don't see the colors, underline ... But
with Android 1.6, I don't have this problem.

I've saw the changelog between 1.5 and 1.6 but nothing ... :s

Any ideas?

-- 

2. Usability: State vs Verb

My business partner and I have a small disagreement, and I'm trying to
figure out the best way to resolve it.

First, I should say I started out his way, and switched after
reviewing a lot of applications.

The background is this -- we have an app, with some controls which can
be locked. A lock/unlock icon is put next to the lockable controls.
You can long-click the icon, and it brings up a context menu with
several items, including the item for the lock state.

Currently, it brings up a "Locked  [X]" or "Locked [ ]" item -- that
is, a menu item with a checkbox that can be checked or unchecked, and
the lock state is changed accordingly.

He would like me to change it to reflect the action being taken. I.e.
the menu item would say "Lock" if it is currently unlocked, and
"Unlock" if it is currently locked.

It would be acting as a toggle in either case; the only difference is
how it is presented to the user.

I see arguments both ways:

* Consistency with platform standards suggests the checkbox.
* This feels more active than the usual "change the state of a
preference flag".

Locking has implications beyond this application -- and is a major
motivation for the application, in fact.

Note that both he and I independently thought at first glance it
should be 'Lock/Unlock'. I need to weigh this apparent intuition
against platform-wide practice and user expectations.

Does anyone have any thoughts or opinions? Or alternatives I perhaps
haven't considered?

Thanks.

-- 

3. Blocking calls

4. Udah Upgrade Radio dan SPL, pas mau upgrade Rom ko tulisan nya can't Mount sdcard nya yah?

5. ListSelector - Not Use or Make More Customised

6. How to shut down phone from within an Application?

7. How to shut down phone from within an Application?